Word-wise diff with moved contents (in Git)

Consider this old text:

aaa bbb ccc
This line moves down.
This line remains here.
So does that one.
Etc.

and this new text:

aaa bbb XXX ccc
This line remains here.
So does that one.
Etc.
This line moves down.

I’d like to show a word-wise diff (git diff --word-diff) with special highlighting to indicate that This line moves down is not simply deleted and inserted, it is the same contents that moves from one place to another. For a line-wise diff, this feature exists as git diff --color-moved. However, this option seems to have no effect on a word-wise diff.

I also tried piping the diff through delta, as advised here; to no avail, although it correctly detects moved lines produced by line-wise git-diff --color-moved. If I understand correctly, delta does not detect moved lines per se, it detects the highlighting put by git diff. So the feature has to be upstream.

  • 1

    “This line moves down is not simply deleted and inserted, it is the same contents that moves from one place to another” Neither Git nor diff has any concept of that.

    – 

  • @matt what about git diff --color-moved then?

    – 

Leave a Comment