Highlighting added/deleted lines, ignoring moves, in a patch file

Viewed 5139

I'm reviewing a patch that moved a lot of things around, added a few things, and removed a few things. I'm wondering if anyone's written a utility for picking out the unique adds/removes in a universal diff?

That is, an add and a remove of the same line should cancel themselves out.

Obviously this isn't useful all the time, but sometimes it's exactly what I want :)

6 Answers

To 'see' only the lines that are not moved, try this in a console with black background

git -c color.diff.newMoved=black -c color.diff.oldMoved=black diff --color-moved=plain --unified=0

All the moved lines will vanish visually. You will see only the lines that are actually changed. Do note that context is also not shown.

Ref: https://groups.google.com/g/git-users/c/kycBnxmmCcU?pli=1

Working solution without additional scripts:

git diff --diff-filter=r origin/master..HEAD

According to man git-diff you can filter all kinds of things (A - added, C - copied, D - deleted, M - modified, R - renamed). Note: lowercase letter means "exclude".

This is a variation of the answer provided by @Zombo above https://stackoverflow.com/a/23462451/722087

When a lot of files have changes that are only moved lines and then there are files that actually have changes other than moved lines then you would want to find those files that have changed lines. The following will allow you to do that.

Copy the file diff-ignore-moved-lines.sh into your path so that you can execute it from anywhere. Then run the following in the git folder

for file in `git diff --name-only`; do  echo $file; git --no-pager diff -- "$file" | diff-ignore-moved-lines; done
Related