46

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.

Stefan
  • 109,145
  • 14
  • 143
  • 218
  • 3
    Check http://stackoverflow.com/a/15149253/1860929 which is available at https://github.com/git/git/blob/master/contrib/diff-highlight/diff-highlight – Anshul Goyal Apr 21 '15 at 08:42

1 Answers1

-2

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

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 1
    This doesn't highlight changed words separately, does it? – Stefan Apr 21 '15 at 08:57
  • The colors scheme i pasted here will highlight the words in the colors you choose to set. simply add it to your .gitconfig and play with the colors to get the desired result. – CodeWizard Apr 21 '15 at 09:00
  • 3
    `git diff --color-words` concatenates the changes (see my 2nd screenshot). I'd like to have two separate lines for each change (just like in `git diff`), but with the changed words / characters highlighted. `git diff` does not seem to support this combined output, choosing different colors doesn't change that. Am I missing something? – Stefan Apr 21 '15 at 09:10
  • Ok, now i fully understood what you want, i didn't understand that you want 2 lines with word highlight. ill be back in few hours and ill test my idea and post it – CodeWizard Apr 21 '15 at 09:11
  • 8
    I'm going to guess that it didn't work? – zneak Aug 06 '18 at 23:34