git diff with combined --word-diff

Stefan picture Stefan · Apr 21, 2015 · Viewed 7.8k times · Source

Given a file with a single word changed, a "normal" git diff looks like this:

normal git diff

Whereas a git diff --word-diff=color looks like this:

git diff with --word-diff

Is it possible to combine the two to get separate lines with the changed words highlighted? Something like this:

combined git diff

It might be trivial, but I couldn't figure it out.

Answer

CodeWizard picture CodeWizard · Apr 21, 2015

The links in the comments shows ways to use extensions and 3rd party to do it.

There is a simple way by adding colors in your git config file. for example

[color "diff"]
    meta = yellow bold
    frag = magenta bold
    old = red
    new = magenta green

Of course you can set any supported color to your needs.

enter image description here