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).
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:
- Arch repository;
- ppa:aos for Debian/Ubuntu Linux;
- a clone of the Git repository.
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:
Happy diffing 😉!