Comprehensive graphical Git diff viewer

Since a long time, I was looking for a graphical git diff viewer which could show original and modified file side-by-side and highlight the changes. There are few solutions but none of them is sufficient:

  • A tool included with git called ‘git-difftool’ is partially helpful – it can show changes graphically but diff for each file is shown one-by-one. This is very irritating. In fact, unusable even with just 10-15 files.
  • Another alternative is the meld diff viewer which is “git aware”. The problem here is that it can show diff for uncommitted changes only which is very limiting. What if you want to see what changes between Linux kernel, say 2.6.33-rc1 and 2.6.33-rc2? or changes between last two commits? meld cannot do it, AFAIK.
  • Finally, with kompare, you can do something like: ‘git diff master | kompare -o -’. This method however, does not show original and new files side-by-side. It is simply prettier diff highlighting.

None of above methods are sufficient. So, I wrote the following script which solves our problem: show complete contents of original and new files side-by-side and highlight the differences.

This script reconstructs a sparse tree containing only the modified files. This allows you to use diff viewer of your choice for nice side-by-side diffs, which is much more helpful than “unified” diffs, especially when differences are complex, or when you are not too familiar with the codebase.

To use it, just use this script (git-diffc) instead of git diff – arguments accepted by these two are identical.

Here is a sample output with the default (meld) diff viewer:

git-diffc filelist

The script allows you to change the diff viewer with the DIFF_BIN environment variable. An interesting case here is to use tree as diff viewer, in case you are simply interested in checking what files were modified across two revisions:

DIFF_BIN=/usr/bin/tree git-diffc HEAD~4 HEAD

Here is the GitHub gist for this script:

linux  git 

See also