git: full-length side-by-side diffs

Got this one from the git-ml (which I read via gmane, but that’s a different post):
I’m not very good at reviewing patches. Especially not if it’s something like JavaScript. git at least colorizes its diffs, which makes it somewhat better. But as soon as you have a big file which is being patched in multiple, disconnected places (different “hunks” in git terminology), so that the context between these hunks is missing, it gets to messy imho.

git-difftool in action

Fortunately there is an easy solution: In git there is contrib/difftool, which makes it easy to display git diffs side-by-side with a viewer of your choice. Of course that meant vimdiff for me. To see all the lines of a file (and not just the changed + a little context) I call git-difftool like this:
git-difftool --tool=vimdiff -U99999Now you can alias that command and use the normal rev-parse arguments. As you can see on the screenshot you can easily distinguish between removed lines, added lines and changed lines. For changed lines the part that was changed is highlighted.

9 Responses to “git: full-length side-by-side diffs”

  1. Cool tip. Added a patched version of dev-util/git to my funtoo fork.

  2. Hehe, cool, now I know that some people on Planet Larrythecow do read my posts :P

  3. Nice. I also like “Kompare” tool which is a graphical diff viewer. It can take input from stdin so piping from Git commands works. Examples:

    git show | kompare -
    git diff HEAD~4.. | kompare -

  4. Yeah, kompare is cool too. Though I prefer vimdiff for the simple reason that I do all my editing/mail-writing in vim and so know my way around the editor and don’t have to re-learn how to do things ;)

  5. difftool doesn’t seem to be part of the git i installed (git version 1.5.6.3)

    i can’t find a contrib directory for git, nor where to download the difftool script.

    i’m kind of clueless. anyone mind stating the obvious? where can i get difftool?

    thanks :-)

  6. Well, difftool isn’t part of the git-installation but part of the git repository, so you gonna have to clone it.
    Second I don’t know in which version difftool was introduced.

  7. difftool is in git 1.6.3 and later.

  8. Wow, cool!

  9. This was a super cool tip. I love vimdiff. A million thanks!