Correct setting for git autocrlf as per use case

自闭症网瘾萝莉.ら 提交于 2019-11-30 09:50:02
VonC

Simple:

 git config core.autocrlf false

(for all and any scenario)

core.autocrlf is a config, which means it is not pushed or cloned with the repo: it has to be set by the user.

It was the legacy way to handle eol at the repo level.

What you want to use (add or modify depending on your scenario) are gitattributes core.eol directives.

  • .gitattributes is a file which can be managed in the git repo like any other file. Once you agree on an eol policy, that policy will be enforced at each clone.
  • you can set core.eol directives for a file, or group of files if you want (as opposed to the global repository-wide config core.autocrlf)

For heterogeneous environment, the core.eol (only for the files you deem problematic) should be native (if you suspect your editor insist on using the system eol instead of using the one already present in the file).

For more, see "Mind the End of Your Line".

Don't worry about core.autocrlf; add a .gitattributes file in the root directory and put the following line in:

* text=auto

This will cause git to automatically convert all line endings to LF on commit, and (for Windows machines) convert line endings to CRLF on checkout.

Note that for use case 1 and 3, where the existing developers are on Windows, adding this line to .gitattributes may make it look like you all of a sudden have a ton of changes to commit. That is because you have a lot of files with CRLF in them in the repository, and git knows it has to convert them all to LF. Go ahead and commit those changes, even though it looks like nothing has really changed.

One other thing to note is that if everyone is on the same OS, then I wouldn't even mess around with converting line endings; in that case, put the line * -text in your .gitattributes file so that no conversion happens.

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