Pages

April 28, 2018

Empowering 'git diff'

The problem

As a "power user" of git (like all of us developers are, aren't we?) I use 'git diff' really often to see, what changes I have made to the code. While examining the diff it is often a pain to visually parse the small changes for some lines, having to compare two or more adjacent lines in the diff. Now you may know (sure you know as a power user…) about 'git diff --color-words', which helps in that regard. But 'git diff --color-words' just kills the other lines or blocks of lines, which changed substantially, leaving us with an unreadable piece of junk, while showing the only slightly changed lines pretty well.

As always, if something (in the software world) is not good enough for us developer users, we strive to improve it. So I searched a pretty long time for a solution to this problem. First I changed the diff.wordRegex to improve stuff, tried to limit the word diffs to single lines. But the word diff of git just does not work this way, it even cannot work this way. It helped a bit (see below for my current wordRegex), but did not solve the problem. I gave up…

Fast forward some months, still being bugged by this problem, I started over to search for a solution. Some days later I stumbled upon diff-highlight, which exactly tries to solve the problem described above. I was instantly hooked, so I tried it out immediately; but only to see that they did not promise too much: "It's currently very simple and stupid about doing these tasks.". But there I saw how it is possible to solve the problem, namely as a post-processing to 'git diff'.

The solution or Welcome to git-diffw