Categories
Uncategorized

git diff-highlight

Diff output from git can be hard to read. Luckily there’s a nice tool bundled with git that can help us out.

Enter diff-highlight, a little perl script found in git’s contrib directory.

From its own documentation:

[diff-highlight] post-processes the line-oriented diff, finds pairs of lines, and highlights the differing segments.

diff-highlight is shipped in a default git install but it needs to be bundled and added to your $PATH. Here’s how to do it on debian:

$ sudo make -C /usr/share/doc/git/contrib/diff-highlight
$ sudo ln -s /usr/share/doc/git/contrib/diff-highlight/diff-highlight /usr/local/bin/

Now you can pipe git’s diff output to to diff-highlight to get a better view of what actually changed.

git diff | diff-highlight

Optionally, you can configure git to use it all the time. Add the following to your ~/.gitconfig:

[pager]
log = diff-highlight | less
show = diff-highlight | less
diff = diff-highlight | less

See the documentation for more usage tips!

Leave a Reply

Your email address will not be published. Required fields are marked *