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:
Thanks! The copy-pasteable commands for setting DiffMerge up as a merge tool are really convenient.
Pingback: Git Merge/Git Difftool: Compare a file between two different branches « The Technological African's Blog
Thanks a lot ! Finally a convenient tool.
Very nice. Thanks!
Cool, I completed the setup in less then 1 minutes.
Great guide! How could this be configured to use “git diff”, instead of “git difftool”, to open DiffMerge?
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”.
Perfect – thanks Chris.
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.
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.
Pingback: Command Line Git Tips | Marion Newlevant: Web Developer
Thanks for the info… this was the one article that got me up and running. Cheers!
Nice one!
Awesome tool!!
Thanks, Aaron
Nice tool. Thank you