Thursday, August 20, 2009

Git diff and difftool, open all files immediately, not in serial

The default behaviour for git diff and git difftool is to open each file in a new window one at a time, only opening the next file after the previous has closed - its a one-by-one, one direction process.

I wanted them to open all at once, so that in a external diff tool such as BeyondCompare all files would open immediately in tabs within a single window.

Hunting around I found a couple of related workarounds (here and here), which involved copying the appropriate before/after files to temp directories and doing a folder diff. But I wanted something simpler, more lightweight, and the breakthrough came when I played with background tasks in bash.

The result of some testing was git diff --name-only to get a file list and git difftool & to diff in a background task; initially using a for-loop, followed by some input/improvements (David and kaizer.se), until the following was finally settled on:

Git diffall

1. Write the following code to a file called git-diffall and place in your path (I put it in …/my-git-install-dir/cmd/ )

#!/bin/sh
git diff --name-only "$@" | while read filename; do
git difftool "$@" --no-prompt "$filename" &
done

2. And run it in git (with usual diff input parameters), for example:

git diffall
git diffall HEAD
git diffall --cached
git diffall rev1..rev2

The initial journey started here at StackOverflow, but I thought this was good content for a first blog post - hope you find it useful.