46

If I execute git diff I see the whole line in red color.

Is there a way to highlight the change in the line?

I often have a diff where just a single line got changed.

Highlighting the change in the line would make git diff more convenient for me.

git-diff-whole-line-red

git version 2.32.0

This should work on the command-line (no GUI).

2

3 Answers 3

65

Use the --word-diff option for git diff

For example, git diff --word-diff=color:

git-diff-word-diff-color

and git diff --word-diff=plain:

git-diff-word-diff-plain

There's also --word-diff-regex=<regex>

See git help diff for more info.

Sign up to request clarification or add additional context in comments.

2 Comments

If you want minimal highlighting, use --word-diff-regex=., which is sometimes clearer (when changs that qualifiy as a "word" get noticeably longer than the "levels" change above, that's clear enough as-is).
The combination of --word-diff=color --word-diff-regex=. allowed me to find a very small change in a very long line in a large merge.
10
+200

If you're willing to use an extra tool, delta is a word-level diff highlighter that does detection of multiple changes in a single line — and also does syntax highlighting (i.e., like GitHub diffs).

If you don’t want syntax highlighting in your diffs, you may also like diff-so-fancy — a great tool I used for years (but which unlike delta, can’t do detection of multiple changes in a single line).

2 Comments

The images you shared are not inline diff though
@alper The question does not ask for an inline solution. It only asks for a solution that shows the change in the line, which according to my interpretation this does.
2

Use colordiff tool colordiff so you can use with the git diff to see all minor changes with color

yum install colordiff # enter yout git repository git diff --word-diff=color 

for example in my directory the tool output the image below

enter image description here:

1 Comment

While colordiff is useful for non-Git usage, the command git diff --word-diff=color operates just with Git’s own resources, it does not use colordiff.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.