sheki
sheki

Reputation: 9349

Git Diff shows unchanged files as removed (with "-")

In a file under a git repository. I have only added some code. When I perform a git diff it shows all the entire older version of the file with a "-", and then displays the entire new version of the file with "+".

For eg.

print "hello"
print "stack overflow" #new added code
print "world"

with git diff shows up as

-print "hello"
-print "world"
+print "hello"
+print "stack overflow" #new added code
+print "world"

Instead of expected

print "hello"
+print "stack overflow" #new added code
print "world"
.

This is causing issues with the reitveld Code review tool as well for me. Am I doing some thing wrong or missing a git config.

Update: Eclipse auto formatted the file, and the spaces went for a toss, and hence the diff was as above. Still there has to be a method to avoid that. Is there anything for that?

Upvotes: 0

Views: 793

Answers (3)

ralphtheninja
ralphtheninja

Reputation: 133008

It might be the case the the file is saved in unix mode (\n) but saved in windows mode (\r\n) therefore causing all lines in the file to be marked as changed. Make sure you save the file in the mode it was stored in.

Upvotes: 2

jfield
jfield

Reputation: 31

Try using:

git diff --ignore-space-at-eol

to ignore the line endings. If this is your issue, unfortunately your commit will still be what you see when you don't use the above flag.

Upvotes: 1

Bombe
Bombe

Reputation: 83852

Check for invisible whitespace, or different line endings (CR vs CR/LF vs LF, depending on the platform and editor you used to create or modify the files).

Upvotes: 3

Related Questions