开发者

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 fil开发者_运维知识库e 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?


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).


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜