78

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.

2
  • Or..... It's correct and you did rewrite the file! Commented Oct 25, 2013 at 15:40
  • 4
    @GabrielePetronella Huh? It's a serious problem I'm still trying to cope with. Commented Jan 4, 2020 at 16:50

1 Answer 1

117

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.

3
  • 14
    go to repo and execute this command git config --global core.autocrlf true Commented Aug 24, 2018 at 8:48
  • ^^ that worked. Android Studio was already set to CRLF Commented Jun 6, 2019 at 22:19
  • You can achieve the same using git UI. stackoverflow.com/a/63062580/3361311
    – Rashid
    Commented Jul 23, 2020 at 20:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.