Visualize per-character differences in a unified diff file

Crosio Kinderstreich 1

When someone sends you a patch, it is most easily viewed with syntax highlighting. The thing you need highlighted is what changed, at a character level.

You get for free with many tools including git (with git diff --word-diff), but this doesn’t help you with a stand-alone patch (diff) file.

Luckily, git ships with diff-highlight! Send a unified diff to that script’s stdin and you get beautiful syntax highlighting, including per-character changes. Here’s a wrapper for diff-highlight for npm users. On my system I found the script at /usr/share/doc/git/contrib/diff-highlight/diff-highlight, and I just run it with the Perl interpreter that ships with my Ubuntu 16.04 desktop.

 

Leave a Reply

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