Why does GitHub think my code has differences?

こ雲淡風輕ζ 提交于 2019-12-25 05:46:07

问题


When I add...

# Auto detect text files and perform LF normalization
* text=auto

...to my config file then the GitHub app/client says that many (if not all?) of the files in the repository have changed. For many of them it says that the entire file has changed even though it obviously hasn't. Obviously this is an issue with line endings but I don't understand why this is happeneing.

It seems that as soon as you tell Git (via the config file) that a file type is text then it throws up differences.


回答1:


With text=auto, Git wants to store the files in LF format--it doesn't simply apply a filter to what is there. As a result, any file that isn't already stored with LF endings will show up as being modified. You probably want to follow the advice on the gitattributes man page in the eol conversion section and do:

$ rm .git/index     # Remove the index to force Git to
$ git reset         # re-scan the working directory
$ git status        # Show files that will be normalized
$ git add -u
$ git add .gitattributes
$ git commit -m "Introduce end-of-line normalization"


来源:https://stackoverflow.com/questions/16082802/why-does-github-think-my-code-has-differences

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