Git can't check out on Linux with LF a file that was stored with CRLF

陌路散爱 提交于 2019-12-02 04:16:11

The problem is that you have core.autocrlf set to true. The documentation says the following:

Setting this variable to "true" is the same as setting the text attribute to "auto" on all files and core.eol to "crlf". Set to true if you want to have CRLF line endings in your working directory and the repository has LF line endings.

You definitely don't want to set that variable to true on a Unix or Linux system; it should be set to false unless you're on a Windows system (and even then there are better alternatives).

You more than likely have set up some of the flags that tell git to mess up with EOL formats (and those flags are a mess). If you would rather have git not mess with them, you can do so by adding this to .gitattributes:

* -text

That way git won mess with the files when you add them or checkout. If you need some other kind of thing (like, real automatic EOL conversion), you might check the available things there.

https://git-scm.com/docs/gitattributes

Either way, steer away from using the flags you used on the question. They are a mess.

Old, but still correct answer about EOL-headache in Git

In short:

core.autocrlf = false 
core.eol = native

will produce correct EOLs on all and any mix of OSes

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