Using DiffMerge as your Git visual merge and diff tool
Our favorite (and free) visual diff and merge tool for OS X (as well as Linux and Windows) is DiffMerge. It makes resolving nasty Git branch conflicts a snap (relatively speaking). Here’s how to install it and configure it with Git on OS X:
Download the DiffMerge OS X installer. Be sure to download the Installer version. There’s also a DMG version but then you’ll have to manually install the diffmerge command line script.
Once you’ve downloaded it go into terminal and make sure you can run it from the command line by typing diffmerge and hitting return.
To configure Git to use DiffMerge run these commands from the command line:
git config --global difftool.diffmerge.cmd 'diffmerge "$LOCAL" "$REMOTE"'
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
git config --global mergetool.diffmerge.trustExitCode true
Now, whenever you want it to launch diffs just use difftool where you’d normally use diff:
git difftool file.m
# diff the local file.m against the version in some-feature-branch
git difftool some-feature-branch file.m
# diff the file.m from the Build-54 tag to the Build-55 tag
git difftool Build-54..Build-55 file.m
To resolve merge conflicts, just run git mergetool:
oripJanuary 2, 2012
Thanks! The copy-pasteable commands for setting DiffMerge up as a merge tool are really convenient.
Git Merge/Git Difftool: Compare a file between two different branches « The Technological African's BlogJanuary 12, 2012
[…] How to setup Git to use Diffmerge to setup DiffMerge as your Git difftool, for Mac OSX you actually need to set the path to DiffMerge like this: [difftool] prompt = NO [difftool "diffmerge"] cmd = ~/Applications/DiffMerge.app/Contents/MacOS/DiffMerge “$LOCAL” “$REMOTE” # For DiffMerge […]
Fredrik JanssonFebruary 1, 2012
Thanks a lot ! Finally a convenient tool.
RyanApril 1, 2012
Very nice. Thanks!
Etile DevApril 4, 2012
Cool, I completed the setup in less then 1 minutes.
Ryan BurnettJuly 11, 2012
Great guide! How could this be configured to use “git diff”, instead of “git difftool”, to open DiffMerge?
Christopher PickslayJuly 13, 2012
Ryan, I don’t know that you can override what git-diff does. If you just don’t want to type out “git difftool”, you could create an alias in your .gitconfig:
df = difftool
Then you’d just type “git df”. Alternately, you could create a shell alias like:
alias gd="git difftool"
Then you’d just type “gd”.
Ryan BurnettJuly 17, 2012
Perfect – thanks Chris.
Prabhath RathmalgodageAugust 14, 2013
Yes. This can be done.
KGNovember 11, 2012
Hi great guide! was just curious, have you tried to use DiffMerge for an interactive way of staging chunks of changes? git comes with two commands “git add -p” and “git commit -p”. these allow you to stage chunks of changes in patches. But they use the command line to show the differences independently, which we would then have to choose to stage.
It would be super awesome to have DiffMerge take care of that as well. Hope that makes sense?
Christopher PickslayNovember 15, 2012
I’m not sure how you’d do that with DiffMerge, but SourceTree is a great free GUI client for git, and it supports staging/unstaging hunks. Check it out at http://www.sourcetreeapp.com.
Command Line Git Tips | Marion Newlevant: Web DeveloperDecember 26, 2012
[…] http://twobitlabs.com/2011/08/install-diffmerge-git-mac-os-x/ http://adventuresincoding.com/2010/04/how-to-setup-git-to-use-diffmerge/ http://gitguru.com/2009/02/22/integrating-git-with-a-visual-merge-tool/ good info on merge tools […]
GregMarch 6, 2013
Thanks for the info… this was the one article that got me up and running. Cheers!
raminMarch 15, 2013
Aaron SmithApril 12, 2013
Ronan O'DriscollMay 2, 2013
Nice tool. Thank you
DennisMay 31, 2013
JayarajJune 23, 2013
Thanks a lot, very helpful
DiffMerge, Git and OS X | Notes to SelfJune 26, 2013
[…] credit due Todd Huss […]
SanjayAugust 13, 2013
Thanks a lot!
John GriffithsAugust 26, 2013
Thanks for posting Todd, been trying a few mergetool’s but keep going back to diffmerge, solid tool.
ScottJanuary 31, 2014
This is just what I was looking for. One questionâ€¦ when I launch it using just “git diff-tool”, it only allows me to open one file at a time. Is there a way to open all the files with differences at once?
Christopher PickslayJanuary 31, 2014
Scott, that’s the default behavior of
git difftool. DiffMerge just doesn’t have a multi-file view. You could try a different GUI diff tool for that. I personally really like Kaleidoscope.
ScottFebruary 1, 2014
suman jakkulaFebruary 5, 2014
You saved my day. Thnx for the article.
Jonathan ChannonJuly 9, 2014
When i run git difftool I get /usr/local/git/libexec/git-core/mergetools/diffmerge: line 121: diffmerge: command not found
Christopher PickslayJuly 9, 2014
Is the path to diffmerge in your .gitconfig correct?
geminiimattAugust 5, 2015
if you get an error like @Jonathan Channon did “/mergetools/diffmerge: line 121: diffmerge: command not found” you can copy the diffmerge.sh to your /usr/bin (assuming your diffmerge is in your applications folder)
sudo cp /Applications/DiffMerge.app/Contents/Resources/diffmerge.sh /usr/bin/
or you can make a symbolic link (recommended) to the diffmerge.sh script
sudo ln -s /Applications/DiffMerge.app/Contents/Resources/diffmerge.sh /usr/bin/diffmerge
good luck with those conflicts people! 🙂
Christopher PickslayAugust 13, 2015
It’s best not to mess with /usr/bin, as that’s owned by the system and installs or restores can wipe it out. If you’re going to symlink the `diffmerge` executable, you should put the symlink in /usr/local/bin.
Alternatively, you can put the full path to diffmerge in your .gitconfig
jitendraOctober 22, 2014
If we are already using Sourcetree do we still need Diffmerge or Kalidoscope?
Christopher PickslayOctober 22, 2014
We use SourceTree as well, and it’s great for diffing your changes. But it doesn’t do merge conflict resolution, so you’ll still need DiffMerge, Kaleidoscope, or another merge tool for that.
JoshOctober 22, 2014
Also got up & running in under a minute. Thanks for the easy reference!
RomanFebruary 9, 2015
OzFebruary 18, 2015
Very nice. Thanks!
Gary MizeSeptember 2, 2015
Any Experience with the online editor CodeAnywhere? I have used DiffMerge on my Mac successfully but when I SSH’d into a “Dev Box” on CodeAnywhere and configured it the same way I get the following “not found” message:
Hit return to start merge resolution tool (diffmerge):
/usr/lib/git-core/git-mergetool: 1: eval: diffmerge: not found
merge of app/Http/Controllers/WizardController.php failed
Any ideas? Is there a different config that’s needed or something….?
Intermediate level | masteringsiomaraSeptember 22, 2015
[…] Diffmerge is use for comparing two files in order to find differences between them. I used the link Ken provided: http://twobitlabs.com/2011/08/install-diffmerge-git-mac-os-x/ […]
michaelMarch 28, 2016
I ran these commands and installed diffmerge, however nothing happens when I run git difftool. No errors or anything. diffmerge is available on the command line. Any ideas what’s wrong?
Christopher PickslayMarch 29, 2016
Do you have local changes? If you run
with no changes in your repo, there’s no data to pass to diffmerge.