A while ago I wrote about the importance of choosing cross-platform development tools when available. As a consultant, being able to work proficiently with multiple platforms provides flexibility in the projects you can choose from. The ability to take a familiar tool with you from one platform to another saves you from having to ramp up on an alternative you’re not used to. It also adds value for your clients allowing you to concentrate precious time on ramping up on the more important domain knowledge specific to the project.

 

DiffMerge is an excellent diff tool that works on all platforms and one I’ve recently adopted as my primary diff tool. Git is easily the best source control system under the sun and also works across platforms. Here I’ll show you how to use them in tandem across Windows, Mac OS X and Ubuntu Linux. Please keep in mind that the actual DiffMerge and Git installation locations may differ on your system requiring a slight tweak or two to the commands below.

 

Mac OS X

Configuring Git to use DiffMerge in Mac OS X is probably the easiest configuration of the three platforms. After installing Git and DiffMerge, you’ll need to run the following Git configuration commands to get up and running.

git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd "/Applications/DiffMerge.app/Contents/MacOS/diffmerge --merge --result=\$MERGED \$LOCAL \$BASE \$REMOTE"
git config --global mergetool.keepBackup false

git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd "/Applications/DiffMerge.app/Contents/MacOS/diffmerge \$LOCAL \$REMOTE"

 

Ubuntu Linux

Configuring Git to use DiffMerge on Ubuntu Linux is very similar to the Mac OS X configuration. The commands are the same here except for the DiffMerge installation location.

git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd "/usr/bin/diffmerge --merge --result=\$MERGED \$LOCAL \$BASE \$REMOTE"
git config --global mergetool.keepBackup false

git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd "/usr/bin/diffmerge \$LOCAL \$REMOTE"

 

Windows

The windows configuration is the most difficult of the three configurations. I wouldn’t even bother trying to set this up using the Git configuration commands through the Git Bash command prompt. You’ll save yourself A LOT of time by just hacking your .gitconfig file manually to point to the external Git scripts required to launch DiffMerge. Here’s what you need to do…

 

1) Create a directory to hold your external Git command scripts – this can be anywhere. I use the ../cmd directory that is created when you install Git on Windows – C:\Program Files (x86)\Git\cmd.

2) Add your Git external command directory to your PATH System Environment Variable.

Right Click ‘Computer’ and choose “Properties” from the context menu.

Click “Advanced System Settings”.

Click the “Environment Variables” button to launch the necessary modal dialog.

 

image

 

3) Drop the following scripts into your Git external commands directory.

git-difftool-diffmerge-wrapper.sh

# place this file in the Windows Git installation directory /cmd folder
# be sure to add the ../cmd folder to the Path environment variable

# diff is called by git with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode

"C:/Program Files (x86)/SourceGear/DiffMerge/DiffMerge.exe" "$1" "$2" | cat

 

git-mergetool-diffmerge-wrapper.sh

# place this file in the Windows Git installation directory /cmd folder
# be sure to add the ../cmd folder to the Path environment variable

# passing the following parameters to mergetool:
# local base remote merge_result

"C:/Program Files (x86)/SourceGear/DiffMerge/DiffMerge.exe" "$1" "$2" "$3" --result="$4" --title1="Mine" --title2="Merge" --title3="Theirs"

 

4) Edit your global .gitconfig file to include the necessary difftool and mergetool commands.

[merge]
    tool = diffmerge
[diff]
    tool = diffmerge
[mergetool]
    keepBackup = false
[mergetool "diffmerge"]
    cmd = git-mergetool-diffmerge-wrapper.sh "$LOCAL" "$BASE" "$REMOTE" "$MERGED"
[difftool "diffmerge"]
    cmd = git-difftool-diffmerge-wrapper.sh "$LOCAL" "$REMOTE"

 

Launch DiffMerge

git mergetool
git difftool

 

Resources

http://adventuresincoding.com/2010/04/how-to-setup-git-to-use-diffmerge

http://support.sourcegear.com/viewtopic.php?f=33&t=13195

http://www.davesquared.net/2009/02/setting-up-diff-and-merge-tools-for-git.html

http://www.davesquared.net/2009/05/setting-up-git-difftool-on-windows.html