Git - End of line characters causing fake diffs

浪尽此生 提交于 2019-12-07 18:52:47

问题


I have a git repository which is hosted in bit bucket. I use source tree to work with git. I have a pull request in which some files appear as modified, but the contents of the file are essentially unchanged. I noticed that when I compared the two branches in bit bucket and source tree. This is what the diff looks like in those tools :

-j1
-j2
-j3
+j1
+j2
+j3

This is very confusing because (1) it makes it appear as though there are many changes, even though there are no real changes, and (2) any changes to a particular line could be missed if you have a huge file (unlike the small one I showed above.)

But, when I compared the two branches in command line (git diff branch1 branch2), I saw that there is a ^M character at the end of each line in one branch which is responsible for the difference.

How do I ensure that end of line characters like ^M, TAB, SPACE etc. get removed in git so that we can avoid confusion in pull requests ? Also, how do I find out why these EOL characters got added in the first place ?


回答1:


Try first

git config --global core.autocrlf false

Then clone again, and make sure there is no diff.
That will ensure there is no "automagic" eol conversion.

Then you can add in a .gitattributes eol directives (example here)



来源:https://stackoverflow.com/questions/58442791/git-end-of-line-characters-causing-fake-diffs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!