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

GitGit Diff

Git Problem Overview


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 https://stackoverflow.com/questions/12876350/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.

Git Solutions


Solution 1 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTiago EspinhaView Question on Stackoverflow
Solution 1 - Gitrob mayoffView Answer on Stackoverflow