I use Subversion to manage source code. Subversion does a pretty good job in handling multiple branches of code and generally keeping things orderly. But it doesn’t seem to do a very good job in merging branch lines back together. To do that properly you really need the help of a three-way merge tool. So today I set out to review some commonly available tools to see what’s what.
The reason you want a three way merge is because every file that you branch, in effect, has three copies. 1) The copy of the file as it was just prior to the time you made the branch: this is the “ancestor” copy. 2) The copy of the file as it exists in the external branch that you’re merging into the code you’re currently working on. 3) The copy of the file in the branch which you’re actively using.
Now managing which is an “active” branch, and in which direction you should merge to/from is beyond the scope of this little review article. (But in general merging from trunk to branch first is usually a good plan, and then back from branch to trunk if your development lifecycle calls for it.)
To test the third party tools out there, I built a reasonably complicated test case with three simple text files that had various changes in them – some of them could reasonably be figured out, some you’d have to be smart to figure out, and some were conflicts that were definitely ambiguous in terms of priority. Here was the general types of conflicts I set up:
1) External branch added a line after branching
2) Working branch added a line after branching
3) External and working added different lines to the same place (I would want to keep both changes)
4) External and working changed the same line in the same place (I would want to choose which to keep)
I felt like this was a pretty reasonable set of conflicts that I have in my day to day programming life.
Here are the results of my very quick and informal merge analysis:
Great UI for conflict resolution. Merge function is smart, and it has such a great interface that you almost don’t resent doing the remaining work yourself. It costs $150 which is double Guiffy and treble ECMerge. KDiff3 is free.
Worse UI (does anyone prefer the Java GUI to native platforms?) Website claims that it has extra logic not available to other tools. This is snakeoil – this tool couldn’t figure out the merges that other tools handled fine. Not impressive.
Nice clean UI for viewing conflicts. Interface for resolving conflicts is clunky and there are some hidden features that I had to guess at (you work with three files A,B,C -> if you want the changes from C followed by the changes from B, you click the button “C” then hold shift and click “B” – if you want to swap from C to B, don’t hold down shift and do the same thing). Exactly as smart as Araxis. Overall the interface for resolving conflicts is mildly annoying but workable – it’s easy to read anyway. Given that it’s a free tool, this tool is highly noteworthy.
Ellie Computing (ECMerge):
Cluttered interface (tons of buttons all over the place). Exactly as smart as Araxis and KDiff3. It had the best functions for resolving conflicts although it’s interface is visually “loud”: it offers functions such as “merge left than right” or “right than left” or “merge inline but prefer right” – these were great options to get the merged code close to final – it’s obvious that the people who built this tool have gone beyond the computer science problem of merging: they realize that real people have to merge and have tried to put interface shortcuts to help you do it.
All the tools allow you to go into the output area and make manual changes to the finished merge to get it exactly right: this is a critical feature. KDiff3’s output window is a little more cluttered b/c of merge messages that are inserted into the output window (but not into the output file when its saved).
Although I didn’t expect this, the overall winner in my opinion, is ECMerge (which I didn’t have any hope for at all based on the crappy website and other poor marketing indicators – just goes to show you). I really liked Araxis’s interface and KDiff3’s did the job.
What I want in a tool is to clear conflict visualization and ease of use in getting the merger to do what you want. Three of the four products accomplish that very well (Guiffy would do in a pinch but I was disappointed in it, and had thought it would do better than it did).
As a bonus, ECMarege, Guiffy and Araxis all have “undo” features which unwind the commands on the output file. So it’s easy to try something out and see what happens and go back if it’s not working. KDiff3 doesn’t seem to support this, and it turned out to be really useful in my testing anyway.
That’s what I’ve learned today, playing around with merge tools. I hope this information is helpful!