git diff 将整个文件视为未更改时已更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19593909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git diff sees whole file as changed when it's not
提问by Tiago Espinha
The git diff engine is seeing a whole file as changed when it has not. For example, take this commit: https://github.com/etiago/phpvirtualbox/commit/626e09958384f479f94011ac3b8301bd497aec51
git diff 引擎将整个文件视为已更改,而实际上并未更改。例如,拿这个提交:https: //github.com/etiago/phpvirtualbox/commit/626e09958384f479f94011ac3b8301bd497aec51
Here we see that the file lib/vboxconnector.phphas 2807 additions and 2778 deletions. Additionally, from doing a manual git diff I find that indeed, the whole file is taken in as a deletion (marked with minus) and a whole new file is taken as an addition. However, the files have a lot in common which Git simply ignored.
在这里我们看到文件lib/vboxconnector.php有 2807 个添加和 2778 个删除。此外,通过手动 git diff 我发现确实,整个文件被视为删除(用减号标记),而一个全新的文件被视为添加。然而,这些文件有很多共同点,Git 只是忽略了。
I've looked at diff returning entire file for identical filesbut it does not seem to be the case as no white space changes exist between the two commits.
我已经查看了diff 返回相同文件的整个文件,但情况似乎并非如此,因为两次提交之间不存在空格更改。
Furthermore, taking the two commits of the file (the one in 626e09958384f479f94011ac3b8301bd497aec51
and 626e09958384f479f94011ac3b8301bd497aec51^1
) and diff'ing them using Meld, I get the right diff analysis.
此外,服用文件(一个在两个提交626e09958384f479f94011ac3b8301bd497aec51
和626e09958384f479f94011ac3b8301bd497aec51^1
),并使用MELD diff'ing他们,我得到正确的差异分析。
I've uploaded the two commits of the file to my Dropbox for convenience: commit_1commit_2.
回答by rob mayoff
In vboxconnector.php_1
, every line is terminated by a CR
LF
sequence.
在 中vboxconnector.php_1
,每一行都由一个CR
LF
序列终止。
In vboxconnector.php_2
, every line is terminated by just LF
.
在 中vboxconnector.php_2
,每一行都以 just 结尾LF
。
Thus every line of the file has changed.
因此文件的每一行都发生了变化。
Try using git diff --ignore-space-at-eol
.
尝试使用git diff --ignore-space-at-eol
.
You may also find some useful information in the answers to this question.
您还可以在此问题的答案中找到一些有用的信息。