我正在审查一个大型重构,它移动了大量文件并更改了一些移动的文件。
当我使用
git diff --summary -M master feature/x
我可以看到许多文件的“相似性百分比”超过 95%,当我使用 git difftool 时,它显示许多文件实际上没有任何更改。
当我使用
git diff --unified -M master feature/x
它显示重命名文件的全部内容,如删除和添加。
我怎样才能让 git diff 只显示它检测为重命名的文件中的更改行?
顺便说一句。 git 使用 --summary 显示的百分比数字究竟是多少?
为什么文件看起来相同时是 97%?
最佳答案
试试这个:
git diff --unified -M master feature/x --color-words
它应该突出显示更改的单词而不是整个文件
您正在使用 -M
用于在 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?
听起来好像有区别(空格)
关于git diff 仅显示重命名文件中更改的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34608127/