我正在查看一个git diff,其中大部分是从一个文件移动到另一个文件的相同代码加上空格。我该如何看到真正的差异?我尝试了git diff -b -C -C
但没有效果。
我是通过另一个SO帖子中的评论了解到这个问题的,但似乎自从git v2.15以来,有能力使用git diff --color-moved
更好地区分移动和更改的代码。
在GitHub git 2.17发布博客文章上有一个很好的示例+屏幕截图,展示了它的用法。
您可以在https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---color-movedltmodegt找到它的帮助/用法。
相关选项包括:
--color-moved[=<mode>]
(模式: no
, default
, plain
, blocks
, zebra
, dimmed-zebra
)--no-color-moved
--color-moved-ws[=<modes>]
(模式: no
, ignore-space-at-eol
, ignore-space-change
, ignore-all-space
, allow-indentation-change
)--no-color-moved-ws
--color-moved-ws
选项的modes
参数似乎是必需的。 - ob-ivan-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有用的评论,目前唯一有效的解决方案是将代码移回原来的位置并在那里进行差异比较。
file-a
移动到file-b
的一个代码块/函数(两者都已经存在)。你能否提供一些简短的示例差异输出?请在你的句子中再详细解释一下。 - try-catch-finally