Can you get a word-diff with `git log`?
Asked Answered
L

2

7

I know that git diff --word-diff=color shows a word diff between the working tree and HEAD, but is there a way to get the same kind of output with git log?

Legionary answered 6/2, 2011 at 4:34 Comment(2)
what version of git are you using? In version 1.5.5.6, git diff --color-words rev1..rev2 only gives expected colored output. If I try git diff --word-diff=color rev1..rev2 it shows the git-diff usage.Hushhush
You might have to write up a little script -- Do git log in such a way that it just prints the SHA1s, then iterate through those SHA1s and do git diff --word-diff=color $SHA1^ $SHA1. Then of course you could assign a git alias to that.Od
A
10

What about --color-words? Additionally you somehow have to activate the diff.

git log --color-words -p

shows me kind of a colored diff.

Avery answered 6/2, 2011 at 4:41 Comment(2)
That outputs line diff, not a word diffLegionary
On 1.7.1 and with my settings (nothing diff-related, apart from maybe color.ui=auto it outputs a word diff.) Of course only when your source contains word differences (= differences smaller than whole added/removed lines).Howells
L
1

OK I think I got it working with

git log -m -p --word-diff=plain
Legionary answered 6/2, 2011 at 6:28 Comment(4)
This gives me a error: fatal: unrecognized argument: --word-diff=plain. What is your git version (git --version)?Howells
git version 1.7.3.2. But on my linux box, which currently has 1.7.0.4, I get the same error.Legionary
So looks like they added the support to --word-diff to git log between these versions (which makes sense, since the option was already possible for git diff).Howells
Nice. Now if only git would use that for actual patches, indenting a block of code might not result in merge conflicts!Irony

© 2022 - 2024 — McMap. All rights reserved.