git diff sees whole file as changed when it's not [duplicate]

五迷三道 提交于 2019-12-03 05:25:43

问题


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

Here we see that the file lib/vboxconnector.php has 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.

I've looked at diff returning entire file for identical files but it does not seem to be the case as no white space changes exist between the two commits.

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.

I've uploaded the two commits of the file to my Dropbox for convenience: commit_1 commit_2.


回答1:


In vboxconnector.php_1, every line is terminated by a CR LF sequence.

In vboxconnector.php_2, every line is terminated by just LF.

Thus every line of the file has changed.

Try using git diff --ignore-space-at-eol.

You may also find some useful information in the answers to this question.



来源:https://stackoverflow.com/questions/19593909/git-diff-sees-whole-file-as-changed-when-its-not

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!