Skip to content

Instantly share code, notes, and snippets.

@rpdelaney
Last active October 13, 2021 16:21
Show Gist options
  • Select an option

  • Save rpdelaney/a462af5a86e4035e63e8673992f4d4ed to your computer and use it in GitHub Desktop.

Select an option

Save rpdelaney/a462af5a86e4035e63e8673992f4d4ed to your computer and use it in GitHub Desktop.

diffing with diffr

colordiff produces diffs that are not always easy to read when a patch has many whitespace changes or minor changes to each line. An upgraded diff tool, such as diffr, can help.

Demo

colordiff

Code getting refactored. But what has changed? colordiff isn't much better than diff here: we can tell which lines have been changed and which are new, but what has been changed in those refactored lines?

diffr

diffr to the rescue. Now we know very quickly that one line was added, and the rest is formatting.

How

macOS

brew install diffr

If you just want stock diffr, here's how to configure git to use it as the diffing engine. (It might look different than in those screenshots, though.):

git config --global pager.diff diffr
git config --global pager.show diffr
git config --global pager.log diffr
git config --global interactive.diffFilter diffr

Here's how I configured the style in the screenshots above. Your terminal emulator must support "intense" and "italic" styles for these settings to work -- but not all do. (Italic support seems to be particularly uncommon.) kitty has all these modern bells and whistles.

brew install kitty
diffr="diffr \
      --colors removed:background:00:foreground:01 \
      --colors refine-removed:background:0:foreground:124:italic \
      --colors added:background:0:foreground:10 \
      --colors refine-added:background:0:foreground:35:intense"

git config --global pager.diff "$diffr"
git config --global pager.show "$diffr"
git config --global pager.log "$diffr"
git config --global interactive.diffFilter "$diffr"

Alternatives

diffr isn't the only option. Other popular extensions to colordiff include:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment