Last Updated: November 29, 2020
·
9.934K
· cam8001

More readable git word diff on macOS or Amazon Linux/CentOS/RedHat

When I make small changes to long lines, the standard git diff display can be a little hard to read.

A community script that improves this view was merged into the git trunk and released with git 1.7.10.

This tip has some brew specific path prefixing - but as long as you specify the path to diff-highlight it will work on any OS.

Before:

Picture

After:

Picture

Find the path to diff-highlight:

  • on macOS, it should be brew --prefix git/share/git-core/contrib/diff-highlight/diff-highlight
  • on RPM based Linux, it should be /usr/share/git-core/contrib/diff-highlight

Add this to your Git config:

# ~/.gitconfig
[core]
   # Using the macOS path here for simplicity. Replace it for your OS.
   pager = `brew --prefix git`/share/git-core/contrib/diff-highlight/diff-highlight | less

Add it with a shell one-liner:

$ git config --global core.pager "`brew --prefix git`/share/git-core/contrib/diff-highlight/diff-highlight | less"

7 Responses
Add your response

You can use $(brew --prefix git)/share/git-core/contrib/diff-highlight

over 1 year ago ·

Thanks! Updated.

over 1 year ago ·

I prefer just setting it in the global config without modifying $PATH. It's already a mess.
And it's all CLI.

git config --global pager.log `brew --prefix`/share/git-core/contrib/diff-highlight/diff-highlight
git config --global pager.show `brew --prefix`/share/git-core/contrib/diff-highlight/diff-highlight
git config --global pager.diff `brew --prefix`/share/git-core/contrib/diff-highlight/diff-highlight
over 1 year ago ·

Much cleaner, thanks! Updated.

over 1 year ago ·

For those who had the same issues when installing this on Git 1.8.3.4 ( installed directly as Github suggest), here is what I had to follow besides this.

cd /usr/local/git/contrib
curl -O https://raw.github.com/git/git/master/contrib/diff-highlight/diff-highlight

And also to add this to my .gitconfig

[core]
  pager = /usr/local/git/contrib/diff-highlight | less
over 1 year ago ·

Suite! Thanks!

over 1 year ago ·

make sure "brew --prefix git" does not appear in ~/.gitconfig, or ruby will be fired up every time you call git diff

with brew --prefix git in ~/.gitconfig

$   time git diff
git diff  0.20s user 0.07s system 94% cpu 0.285 total

with absolute path in ~/.gitconfig

$ time git diff
git diff  0.05s user 0.04s system 92% cpu 0.095 total
over 1 year ago ·