Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git diff displaying only changed lines in renamed files

Tags:

git

git-diff

I'm reviewing a big refactor which moved plenty of files around and changing some of the moved files.

When I use

git diff --summary -M master feature/x

I can see many files that have 'similarity percentage' above 95% and when I use git difftool it shows that many of files don't actually have any changes.

When I use

git diff --unified -M master feature/x

it displays the whole contents of renamed files, as removed and then added.

How can I make git diff show me only changed lines in files that it detected as renames?

BTW. What exactly it the percentage number that git displays with --summary?
Why is it 97% when the files look the same?

like image 865
tymtam Avatar asked Feb 03 '26 18:02

tymtam


1 Answers

Try this out:

git diff --unified -M master feature/x --color-words

It should highlight the words that were changed and not the whole file

enter image description here


You are using the -M which is used to display renamed files in the diff.

-M[<n>] --find-renames[=<n>]

Detect renames. If n is specified, it is a threshold on the similarity index (i.e. amount of addition/deletions compared to the file's size). For example, -M90% means Git should consider a delete/add pair to be a rename if more than 90% of the file hasn't changed. Without a % sign, the number is to be read as a fraction, with a decimal point before it. I.e., -M5 becomes 0.5, and is thus the same as -M50%. Similarly, -M05 is the same as -M5%. To limit detection to exact renames, use -M100%. The default similarity index is 50%.

Why is it 97% when the files look the same? Have you checked that your white space configuration ignore white space diffs?

Sounds like there is a difference in that (white spaces)

like image 191
CodeWizard Avatar answered Feb 06 '26 07:02

CodeWizard