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 and highlight the differences.
This script reconstructs (sparse) tree containing modified files. This is very useful with large projects like the Linux kernel – there is one Kconfig file in each directory, which is the one this change modified!
To use it, just use the script instead of ‘git diff’ directly. Arguments to this script are the same as if you are using git-diff command. See script comments for further help.
Lets see some examples:
1) I have a ‘qemu-kvm’ git tree with some uncommitted changes. In this tree ‘git diff’, without any arguments, would generate the diff. So, we do the same with git-diffc. git-diffc
2) I want to see difference between Linux kernel 2.6.33-rc1 and 2.6.33-rc2. This can be done with ‘git diff v2.6.33-rc1 v2.6.33-rc2’ which will generate unified diff between these two releases. To get graphical diff (note: we always use same args as git-diff): git-diffc v2.6.33-rc1 v2.6.33-rc2
Here is the output with default (kdiff3) diff viewer:
Note that entire directory hierarchy is reconstructed which is almost essential for such large projects. A simple flat list of changed files will be almost useless. As another example if you were simply interested in checking what files are modified across these two versions, you could do: DIFF_BIN=/usr/bin/tree git-diffc v2.6.33-rc1 v2.6.33-rc2
The same command as above, but overriding diff viewer (see script comments for details). I hope you will find this script useful. Happy Hacking and Happy New Year!
You can download the script from here.