git diff 仅显示重命名文件中更改的行

标签 git git-diff

我正在审查一个大型重构,它移动了大量文件并更改了一些移动的文件。

当我使用

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

它应该突出显示更改的单词而不是整个文件

enter image description here


您正在使用 -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/

相关文章:

git - 在 cPanel 中创建 git repo 时出现问题

ruby - 如何将版本历史从 Serena Dimensions 导出到 Git?

macos - Git 没有使用我的 $PATH 中的第一个编辑器

git - 为什么 git diff 显示修改后的相同文件?

python - 用于从文件中选择单个 Python 函数的 Bash 脚本

git-diff - 如何在 git diff 中显示完整路径?

git - 如何确定我使用的是 32 位还是 64 位版本的 Git

git - 如何搜索提交中的所有删除内容?

两个不同文件夹中两个不同存储库之间的git diff

git - git 可以在 repo 文件和外部(非 repo )文件之间进行区分吗?