March 7, 2013

Configure git to use a different tool for diffing

I don't like default git diff output: I prefer vimdiff or tkdiff. Here is a recipe that explains how to set up external diff.
Your basic ~/.gitconfig should have [diff] section as in:
[user]
        name = <your name>
        email = <your@email>
[color]
        status = auto
        diff = auto
        branch = auto
        interactive = auto
[core]
        editor = vim
        pager = less -FRSX
[diff]
        external = /home/<username>/bin/gittkdiff.sh
[merge]
        tool = vimdiff
Create external gittkdiff.sh and make it executable (chmod +x):
#!/bin/sh

/usr/bin/tkdiff "$2" "$5" | cat
For vimdiff use:
#!/bin/sh

/usr/bin/vimdiff "$2" "$5" | cat



[Update - 08/10/2014]

Newer git can do this for you:
git config --global diff.tool tkdiff
git config --global merge.tool tkdiff
git config --global --add difftool.prompt false