我正在看一个git diff,大部分都是从一个文件移到另一个文件加上空格的相同代码。我怎么能看到真正的差异?我试过git diff -b -C -C
无济于事。
答案 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上找到其帮助/用法
相关选项包括:
--color-moved[=<mode>]
(模式:git diff --color-moved
,no
,default
,plain
,blocks
,zebra
)--no-color-moved
--color-moved-ws[=<modes>]
(模式:dimmed-zebra
,no
,ignore-space-at-eol
,ignore-space-change
,ignore-all-space
)--no-color-moved-ws