← back to articles

stevemao/diff-so-fancy

Save article ToRead Archive Delete · Log out

1 min read · View original · github.com

diff-so-fancy

diff-so-fancy builds on the good-lookin' output of git contrib's diff-highlight to upgrade your diffs' appearances.

Screenshot

git diff vs git diff --color | diff-so-fancy

diff-highlight vs diff-so-fancy

Usage

You can do one-off fanciness:

git diff --color | diff-so-fancy

But, you'll probably want to fancify all your diffs. Run this so git diff will use it:

git config --global core.pager "diff-so-fancy | less --tabs=1,5 -R"

Or, create a git alias in your ~/.gitconfig for shorthand fanciness:

dsf = "!git diff --color $@ | diff-so-fancy"

Install

For convenience, the recommended installation is via NPM:

npm install -g diff-so-fancy

This will install and link the diff-so-fancy and diff-highlight scripts.

Manual installation alternative

If you want, you can choose to install manually:

Note: The diff-highlight dependency is an official git-contrib script, duplicated here for convenience. If you prefer less fancy in your diff, you also use diff-highlight on it's own.

Install GNU sed

You'll need GNU sed. On Mac, it's easy to install with Homebrew.

brew install gnu-sed --with-default-names  # Without the default-names flag, you'll have to use it via `gsed`

Improved colors for the the highlighted bits

diff-highlight has default colors that are arguably a little nasty. They'll work fine, but you can try some fancier colors:

git config --global color.diff-highlight.oldNormal "red bold"
git config --global color.diff-highlight.oldHighlight "red bold 52"
git config --global color.diff-highlight.newNormal "green bold"
git config --global color.diff-highlight.newHighlight "green bold 22"

You may also want to configure general diff colors.

Opting-out

Sometimes you will want to bypass diff-so-fancy. Easy enough:

git --no-pager diff  # will avoid the global core.pager hook

Credit

Originated from https://github.com/paulirish/dotfiles/blob/master/bin/diff-so-fancy