nl-bdg
Last Updated: November 02, 2018
·
7.542K
· cam8001

More readable git word diff on OSX

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

Add this to your Git config:

# ~/.gitconfig
[core]
   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"

8 Responses
Add your response

10579

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

over 1 year ago ·
10580

Thanks! Updated.

over 1 year ago ·
10595

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 ·
10628

Another solution which is more clean:

# ~/.gitconfig
[core]
    pager = `brew --prefix`/share/git-core/contrib/diff-highlight/diff-highlight | less
over 1 year ago ·
10647

Much cleaner, thanks! Updated.

over 1 year ago ·
10722

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 ·
10950

Suite! Thanks!

over 1 year ago ·
18949

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 ·