Git protip: a nice and efficient diff in the console
By Maxime Bréhin • Published on 28 August 2022 • 1 min

Cette page est également disponible en français.

The standard Git diff prints tons of information, some are not essential and make what’s printed harder to read. The key issues are that we can’t clearly see file boundaries (where does one end, and the next one start?) and that single-line changes are printed as two separated lines (delete/add), so we struggle in analyzing what changed on a specific line (it’s kind of like a “spot the difference” game).

The diff in the console lacks clarity

We looked at what options and configuration the diff command offered to improve that display, but that wasn’t good enough. So we searched for a third-party tool that might help in the console. We wanted it to be easy to install and use. This is how we found diff-so-fancy.

There are many ways to install it easily:

The most portable way to install it is through npm:

npm install --global diff-so-fancy

Once it is installed, you must instruct Git to use it; add this to your global config:

git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"
git config --global interactive.diffFilter "diff-so-fancy --patch"

You can also customize colors and some of the behavior, but the default settings are great already.

With this set up, you now get a display like this one:

The diff is more sexy with diff-so-fancy

Happy diffing 😉!

Protips galore!

We got tons of articles, with a lot more to come. Also check out our kick-ass training courses 🔥!