Configuring Git and Mercurial to use DiffMerge
My preferred merge/diff tool at the moment is DiffMerge by SourceGear. Besides normal diff and also folder diffs, it supports three-way merging and has a pretty sweet, intuitive UI with a-well chosen colour scheme and excellent shortcuts. The reason it is my tool du jour is its perfect cross-platform implementation supporting Windows, MacOS X and Unix. The feature set (and the UI!) is same on all platforms. Remembering only the workings of one diff tool significantly reduces friction for me.
Integrating DiffMerge with the various VCS I use (mercurial, git and svn) is quite cumbersome, but is fortunately very well possible. I’ll post my sample configurations here. The configuration files are alway located in the user’s home directory. Configuration is the same for Windows/Mac OS X and Unix, however you’ll have to adapt the path to the DiffMerge executable accordingly.
[diff] git = True [extensions] hgext.extdiff = [ui] merge = diffmerge [extdiff] cmd.diffmerge = c:\Programme\SourceGear\DiffMerge\DiffMerge.exe [tortoisehg] vdiff = diffmerge [merge-tools] diffmerge.executable = c:\Programme\SourceGear\DiffMerge\DiffMerge.exe diffmerge.args = --result=$output -t1="Local Version" -t2=$output -t3="Other Version" --caption=$output $local $base $other diffmerge.binary = False diffmerge.symlinks = False diffmerge.gui = True diffmerge.premerge = True
Mercurial will fire up DiffMerge during merges automatically from now on. Since the built-in diff command will always print directly to console (you can pipe this into a patch file too, very useful!) you need the extdiff extension to enable diffing with DiffMerge. That’s why TortoiseHg also needs to be configured explicitly to use DiffMerge as visual diff tool.
[mergetool "diffmerge"] cmd = diffmerge --merge --result=$MERGED $LOCAL $BASE $REMOTE trustExitCode = true [diff] tool = diffmerge [difftool "diffmerge"] cmd = diffmerge \"$LOCAL\" \"$REMOTE\"
Git does not merge automatically but will rather leave merge markes in the file. You have to use
git mergetool -t diffmerge
to bring up DiffMerge. On the web one can find recommendations to set
trustExitCode = false
when using DiffMerge. Since v 3.1. this is no longer needed because DiffMerge now returns correct status codes indicating whether a merge was successful or failed.