Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-diff

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.

like image 533
Tiago Espinha Avatar asked Oct 25 '13 15:10

Tiago Espinha


People also ask

How do I remove unchanged files in git?

Recent versions of git require either "-f" (force) or "-n" (dry-run) to be specified. I use this so often, that I have an alias for this (added to your . gitconfig ) to check for files that would be deleted when you run git clean .

Why git diff does not show changes?

Your file is already staged to be committed. You can show it's diff using the --cached option of git. To unstage it, just do what git status suggests in it's output ;) You can check The Git Index For more info.

What does git diff show you?

By default git diff will show you any uncommitted changes since the last commit.

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.


1 Answers

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.

like image 156
rob mayoff Avatar answered Sep 17 '22 15:09

rob mayoff