移动代码后如何查看git更改?

时间:2013-05-23 00:58:28

标签: git diff

我正在看一个git diff,大部分都是从一个文件移到另一个文件加上空格的相同代码。我怎么能看到真正的差异?我试过git diff -b -C -C无济于事。

3 个答案:

答案 0 :(得分: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 :(得分:1)

根据kampu的有用评论,到目前为止,唯一可行的解​​决办法是将代码移回原来的地方并在那里进行差异化。

答案 2 :(得分:1)

我通过a comment in another SO post遇到了这个问题,但似乎since git v2.15可以使用select companyid, max(conid) from contacts group by companyid having count(*) = 1 and companyid in (select ccyid from companies where primconid is null) order by companyid; 来更好地区分移动代码和更改代码。

GitHub git 2.17 release blog post上也有一个不错的示例+屏幕截图。

您可以在https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---color-movedltmodegt上找到其帮助/用法

相关选项包括: