Resolve Bazaar Merge Conflicts with Emacs

How to fix bizarre merge conflicts with emacs will be in a different chapter. Here you will just find tips for working with the Bazaar revision control system, also known as, bzr. This assumes you are fairly comfortable with the basics of bzr and emacs.

When you do a bzr merge to pull in changes from a different branch (try bzr pull first, it will tell you if you need to bzr merge instead), it's possible that conflicting edits have been made to the files you are versioning. In that case bzr will tell you about it, and drop three new files in your directory tree for each file with conflicts. They will be named, file.THIS, file.OTHER, and file.BASE. "Whoa! Scary! What do I do with all of these?" you might say to yourself. I'm here to answer that question, with a handy emacs tool called ediff. Open emacs and and type M-x ediff-merge-with-ancestor. It will ask for three files, which you should give in this order: file.THIS, file.OTHER, and file.BASE. It will split the screen so you see two buffers side-by-side and a third below them. Another little window, the ediff windows, will pop up as well. With the ediff window active you can hit some special keys to navigate through the differences in the files. Most importantly, n and p step through diffs, and v scrolls down a few lines, V scrolls up a few lines (and hit ? for more help). Your changes are on the left, changes incoming are on the right.

It's really easy to resolve the merge conflicts, just start stepping through the diffs by hitting n. Watch the bottom window (emacs window, more like what you might call a frame these days), you really only need to pay attention when it shows two alternative choices and the original. That's where a conflict occurred. Just hit a or b to choose which of the two changes you'd like to keep. If they aren't exactly right, you can edit the file right there in place in the bottom window.

When you have resolved all the conflicts this way, you hit q to quit the ediff session. Then you can save the bottom buffer right over top of the original file (c-x c-s, y). Go to your command-line and type bzr resolve file. Once you resolve all the conflicts like this you can bzr ci and you have successfully merged and resolved conflicts like a pro.

P.S. After figuring all that out, I found some good ediff-merge-with-ancestor tips out on the web (with svk, not bzr, but still helpful). Go figure.

Comments

Popular posts from this blog

SystemVerilog Fork Disable "Gotchas"

'git revert' Is Not Equivalent To 'svn revert'

Git Rebase Explained