While there are some great diff tools out there, there are very few good merge tools. My favorite diff tool is Kaleidoscope. And there are several others I wouldn’t mind using.

However, Kaleidoscope does not do merging. Too me, software development requires much more merging then diff’ing. And many times, github.com’s HTML diff view is more than sufficient. Heck, even command line diff works just fine for small differences. Looking at diff’s is easy and paying money for a tool that only does diffs is something I find hard to swallow.

Taking three files, and coming up with a new one is quite a bit more difficult. In my experience, not many tools handle it well. The biggest problems are:

  • Integration and interoperability with the OS (cough, OS X native)
  • Intelligent resolution of conflicts
  • Differences within a line
  • Easily choosing which diff chunks to take
  • Being able to edit the final merged file

Many times, the merge tool will not be fine grained enough to allow for differences within a line to be accurately merged. You’ll even have problems with whole lines of code not being intelligently merged.

The two best tools I’ve found to handle this are:

Araxis Merge was originally a windows product that I used in a previous life. It was great because it offered not just merging, but standard diffs, as well as directory diffs. Really nice and I highly recommend. However, I don’t use it anymore, even though they have a Mac version. The problem is the price is absurd: $269 and then $49 a year, thereafter. That’s insane.

Especially insane, when the next best tool is free! P4Merge is actually from another SCM company, Perforce. It is more of a single purpose tool then something like Araxis Merge. However, it does do merging very well. I’ve found that it can start to get confused on resolving conflicts, such as when an existing chunk of code is just moved down the file while another commit inserted new code at the same spot. But that’s where being able to edit the final merged file at the same time helps.

P4Merge

(Notice the yellow, blue, and green icons on the right side of the bottom pane. You click each one to switch which code is used in the final output.)

You would think that using P4Merge with a competing SCM like git would not be easy. But it’s actually quite straightforward. Go install P4Merge and then just add this to ~/.gitconfig:

[merge]
        keepBackup = false
        tool = custom

[mergetool "P4Merge"]
        cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "$PWD/$BASE" "$PWD/$REMOTE" "$PWD/$LOCAL" "$PWD/$MERGED"
        keepTemporaries = false
        trustExitCode = false
        keepBackup = false

When you need to merge with git, run

git mergetool

Instead of the normal, git merge. The one problem I’ve run into is that even though keepTemoraries/keepBackup is false, I still get .orig files littered about when a merge happens. These have to be cleaned up manually.

mike: Mike is an opinionated computer programmer living in Michigan with his wife and three kids.

Discussion

No comments yet, be the first.

Leave a Comment