移动代码后如何查看git的变化?

问题描述 投票:0回答:3

我正在查看git diff,其中大多数是从一个文件移动到另一个文件再加上空格的相同代码。我怎么能看到真正的差异?我尝试git diff -b -C -C无济于事。

git diff
3个回答
1
投票

使用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.

1
投票

基于kampu的有用注释,到目前为止,唯一可行的解​​决方案是将代码移回原始位置并在此处进行比较。


0
投票

我通过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上找到它的帮助/用法>

相关选项包括:

© www.soinside.com 2019 - 2024. All rights reserved.