Using DiffMerge as your Git visual merge and diff tool

Posted by on Aug 17, 2011 in code, Git, Mac OS X, Software Development | 38 Comments

Install DiffMerge for Git on Mac OS XOur 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 diff.tool diffmerge
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:

# diff the local file.m against the checked-in version
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:

git mergetool

38 Comments

  1. orip
    January 2, 2012

    Thanks! The copy-pasteable commands for setting DiffMerge up as a merge tool are really convenient.

    Reply
  2. 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 […]

    Reply
  3. Fredrik Jansson
    February 1, 2012

    Thanks a lot ! Finally a convenient tool.

    Reply
  4. Ryan
    April 1, 2012

    Very nice. Thanks!

    Reply
  5. Etile Dev
    April 4, 2012

    Cool, I completed the setup in less then 1 minutes.

    Reply
  6. Ryan Burnett
    July 11, 2012

    Great guide! How could this be configured to use “git diff”, instead of “git difftool”, to open DiffMerge?

    Reply
    • Christopher Pickslay
      July 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:

      [alias]
          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”.

      Reply
    • Prabhath Rathmalgodage
      August 14, 2013

      Yes. This can be done.
      http://jeetworks.org/node/90

      Reply
  7. KG
    November 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?

    Cheers.

    Reply
  8. Greg
    March 6, 2013

    Thanks for the info… this was the one article that got me up and running. Cheers!

    Reply
  9. ramin
    March 15, 2013

    Nice one!

    Reply
  10. Aaron Smith
    April 12, 2013

    Awesome tool!!

    Thanks, Aaron

    Reply
  11. Ronan O'Driscoll
    May 2, 2013

    Nice tool. Thank you

    Reply
  12. Dennis
    May 31, 2013

    Thank you!

    Reply
  13. Jayaraj
    June 23, 2013

    Thanks a lot, very helpful

    Reply
  14. DiffMerge, Git and OS X | Notes to Self
    June 26, 2013

    […] credit due Todd Huss […]

    Reply
  15. Sanjay
    August 13, 2013

    Thanks a lot!

    Reply
  16. John Griffiths
    August 26, 2013

    Thanks for posting Todd, been trying a few mergetool’s but keep going back to diffmerge, solid tool.

    Reply
  17. Scott
    January 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?

    Reply
    • Christopher Pickslay
      January 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.

      Reply
      • Scott
        February 1, 2014

        Thanks!

        Reply
  18. suman jakkula
    February 5, 2014

    You saved my day. Thnx for the article.

    Reply
  19. Jonathan Channon
    July 9, 2014

    When i run git difftool I get /usr/local/git/libexec/git-core/mergetools/diffmerge: line 121: diffmerge: command not found

    Any ideas?

    Reply
    • Christopher Pickslay
      July 9, 2014

      Is the path to diffmerge in your .gitconfig correct?

      Reply
    • geminiimatt
      August 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! 🙂

      Reply
      • Christopher Pickslay
        August 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

        Reply
  20. jitendra
    October 22, 2014

    If we are already using Sourcetree do we still need Diffmerge or Kalidoscope?

    Reply
    • Christopher Pickslay
      October 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.

      Reply
  21. Josh
    October 22, 2014

    Also got up & running in under a minute. Thanks for the easy reference!

    Reply
  22. Roman
    February 9, 2015

    cool. thanks

    Reply
  23. Oz
    February 18, 2015

    Very nice. Thanks!

    Reply
  24. Gary Mize
    September 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….?

    Thanks

    Reply
  25. 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/ […]

    Reply
  26. michael
    March 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?

    Reply
    • Christopher Pickslay
      March 29, 2016

      Do you have local changes? If you run

      git difftool

      with no changes in your repo, there’s no data to pass to diffmerge.

      Reply

Leave a Reply