我正在查看git diff,其中大多数是从一个文件移动到另一个文件再加上空格的相同代码。我怎么能看到真正的差异?我尝试git diff -b -C -C
无济于事。
使用git diff的-M
选项:
-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.
和-w
:
-w, --ignore-all-space
Ignore whitespace when comparing lines. This ignores
differences even if one line has whitespace where the
other line has none.
基于kampu的有用注释,到目前为止,唯一可行的解决方案是将代码移回原始位置并在此处进行比较。
我通过a comment in another SO post遇到了这个问题,但是since git v2.15似乎可以使用git diff --color-moved
更好地区分已移动和已更改的代码。
[还有一个不错的示例+屏幕截图也显示了GitHub git 2.17 release blog post上的用法。
您可以在https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---color-movedltmodegt上找到它的帮助/用法>
相关选项包括:
--color-moved[=<mode>]
(模式:--color-moved[=<mode>]
,no
,default
,plain
,blocks
,zebra
)]dimmed-zebra
--no-color-moved
(模式:--no-color-moved
,--color-moved-ws[=<modes>]
,--color-moved-ws[=<modes>]
,no
,ignore-space-at-eol
)]ignore-space-change