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:
38 Comments
orip
January 2, 2012Thanks! 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 Blog
January 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 Jansson
February 1, 2012Thanks a lot ! Finally a convenient tool.
Ryan
April 1, 2012Very nice. Thanks!
Etile Dev
April 4, 2012Cool, I completed the setup in less then 1 minutes.
Ryan Burnett
July 11, 2012Great guide! How could this be configured to use “git diff”, instead of “git difftool”, to open DiffMerge?
Christopher Pickslay
July 13, 2012Ryan, 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 Burnett
July 17, 2012Perfect – thanks Chris.
Prabhath Rathmalgodage
August 14, 2013Yes. This can be done.
http://jeetworks.org/node/90
KG
November 11, 2012Hi 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?
Cheers.
Christopher Pickslay
November 15, 2012I’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 Developer
December 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 […]
Greg
March 6, 2013Thanks for the info… this was the one article that got me up and running. Cheers!
ramin
March 15, 2013Nice one!
Aaron Smith
April 12, 2013Awesome tool!!
Thanks, Aaron
Ronan O'Driscoll
May 2, 2013Nice tool. Thank you
Dennis
May 31, 2013Thank you!
Jayaraj
June 23, 2013Thanks a lot, very helpful
DiffMerge, Git and OS X | Notes to Self
June 26, 2013[…] credit due Todd Huss […]
Sanjay
August 13, 2013Thanks a lot!
John Griffiths
August 26, 2013Thanks for posting Todd, been trying a few mergetool’s but keep going back to diffmerge, solid tool.
Scott
January 31, 2014This 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 Pickslay
January 31, 2014Scott, 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.Scott
February 1, 2014Thanks!
suman jakkula
February 5, 2014You saved my day. Thnx for the article.
Jonathan Channon
July 9, 2014When i run git difftool I get /usr/local/git/libexec/git-core/mergetools/diffmerge: line 121: diffmerge: command not found
Any ideas?
Christopher Pickslay
July 9, 2014Is the path to diffmerge in your .gitconfig correct?
geminiimatt
August 5, 2015if 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 Pickslay
August 13, 2015It’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
jitendra
October 22, 2014If we are already using Sourcetree do we still need Diffmerge or Kalidoscope?
Christopher Pickslay
October 22, 2014We 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.
Josh
October 22, 2014Also got up & running in under a minute. Thanks for the easy reference!
Roman
February 9, 2015cool. thanks
Oz
February 18, 2015Very nice. Thanks!
Gary Mize
September 2, 2015Any 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….?
Thanks
Intermediate level | masteringsiomara
September 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/ […]
michael
March 28, 2016I 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 Pickslay
March 29, 2016Do you have local changes? If you run
with no changes in your repo, there’s no data to pass to diffmerge.