Skip to content

Instantly share code, notes, and snippets.

@psebborn
Created July 21, 2015 11:33
Show Gist options
  • Save psebborn/d08faa0fe4c016a41a31 to your computer and use it in GitHub Desktop.
Save psebborn/d08faa0fe4c016a41a31 to your computer and use it in GitHub Desktop.

#Merging with graphical diff tools

First things first

It's worth trying to just run git difftool or git mergetool as by default most Git installations will configure your OS's diff tool (Meld for Ubuntu, and FileMerge / Opendiff for OSX).

There are two ways of updating the merge tools that Git will use by default. The first is to copy the config straight into your .gitconfig file (usually in your home folder). If you're not happy doing that you can use git config, e.g.:

git config --global diff.tool diffmerge
git config --global diffmerge.cmd "diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$(if test -f \"$BASE\"; then echo \"$BASE\"; else echo \"$LOCAL\"; fi)\" \"$REMOTE\""

You'll end up with the same thing whichever way you do it (can also review this with git config -l) so it's a case of personal preference.

Diffmerge

This isn't free, but it is really nice.

[merge]
    tool = diffmerge
[mergetool "diffmerge"]
    cmd = "diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$(if test -f \"$BASE\"; then echo \"$BASE\"; else echo \"$LOCAL\"; fi)\" \"$REMOTE\""
    trustExitCode = true

[diff]
    tool = diffmerge
[difftool "diffmerge"]
    cmd = diffmerge \"$LOCAL\" \"$REMOTE\"
    
[merge]

(NB: The 'cmd' option might not be needed as Git bash already have this configured. Try without it to start with and add it in if you get errors).

KDiff3

Not as pretty as Diffmerge but it is open source, therefore free, which will appeal to a lot of people. Along with Diffmerge you can install this with apt-get install (OSX may be able to use Homebrew, otherwise you'll have to download the binary from the website Config looks like this:

[diff]
    tool = kdiff3

[merge]
    tool = kdiff3
    

('cmd' argument isn't needed as Git knows how to handle KDiff3).

Others

By default OSX will use filemerge. Ubuntu will use meld. Both are ok, but not very easy to use, particularly when merging as they won't automatically try to merge conflicts (so it's easy to lose changes without realising)

Diffmerge is the prettiest, but for set up KDiff3 is much more straightfward. Also, you can do : git difftool -d to do a 'dir-diff' (open one window with all the changes in a tree structure) git difftool file_name to just open one specific file. This should also work with mergetool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment