git-difftool: an easy way to highlight changes in git-managed text files

In two previous posts (post one, post two) we have shown how to use git latexdiff and latexdiff to visually highlight the differences of a Latex file in between its different versions in the form of a Latex-compiled diff file. For comparing arbitrary textfiles instead of Latex files, no Latex-based visual comparison is available. However, git itself ships a nice little tool to compare two different versions of the same textfile and highlight its differences: git difftool. It basically does two things for you:

  • Checkout the versions of the file to compare
  • Fire up your diff program to show you/highlight the differences

All you need to do is specify the file and the versions you want to compare.



git difftool is part of the git installation. However, it needs to know which diff program you want to use when calling git difftool. You can specify this by adding the following snippet to your ~/.gitconfig:

    tool = MY-DIFF-TOOL

where MY-DIFF-TOOL could be vimdiff, kdiff3, or similar (ensure the tool you specify is installed and available in the PATH on your machine). Now git difftool should be ready for usage:

user@machine:~$ git difftool -h
usage: git difftool [-t|--tool=] [--tool-help]
                    [-g|--gui] [--no-gui]
                    [--prompt] [-y|--no-prompt]
                    ['git diff' options]


git difftool has a simple call syntax (in fact the same as git diff). The command you might want to compare files might be similar to this:

git difftool COMMIT1 COMMIT2 FILE

If you use


as COMMIT1 and leave out COMMIT2 you will see the differences between the file in its current, possibly unstaged/uncommited stage and its last commit. If you specify a hash for COMMIT1 and use


as COMMIT2 you will see the differences of the current file to the specified commit instead. If you specify hashes for both COMMIT1 and COMMIT2 you will see the differences between those two versions of the file.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s