问题描述
我正在寻找根据某些用例使用的正确设置,但找不到任何描述相同的来源.因此,我问这个问题是为了给任何寻找 git 的 autocrlf 选项正确设置的人提供解决方案.
I was searching for the proper setting to be used as per certain use cases but could not find any source describing the same. Therefore, I am asking this question to serve as a solution to anyone looking for the correct setting for git's autocrlf option.
用例 1:我在 Mac 上,其他开发人员都在 Windows 上.在我加入之前,他们正在管理源代码.
Use Case 1: I am on Mac, the other developers are all on Windows. They are managing the source code before I joined in.
用例 2:我在 Windows 上,其他开发人员都在 Mac 上.在我加入之前,他们正在管理源代码.
Use Case 2: I am on Windows, the other developers are all on Mac. They are managing the source code before I joined in.
用例 3: 我在 Linux 上,其他开发人员都在 Windows 上.在我加入之前,他们正在管理源代码.
Use Case 3: I am on Linux, the other developers are all on Windows. They are managing the source code before I joined in.
用例 4: 我在 Windows 上,其他开发人员都在 linux 上.在我加入之前,他们正在管理源代码.
Use Case 4: I am on Windows, the other developers are all on linux. They are managing the source code before I joined in.
用例 5:我在 Linux 上,其他开发人员都在 Mac 上.在我加入之前,他们正在管理源代码.
Use Case 5: I am on Linux, the other developers are all on Mac. They are managing the source code before I joined in.
用例 6:我在 Mac 上,其他开发人员都在 Linux 上.在我加入之前,他们正在管理源代码.
Use Case 6: I am on Mac, the other developers are all on Linux. They are managing the source code before I joined in.
我应该使用 git core.autocrlf 的什么设置?
What setting of git core.autocrlf should I be using ?
为什么这个问题与许多类似问题不同:
所有其他问题及其答案都提供了所需的事实和知识,让读者有很多事情要做.这个问题旨在针对特定场景询问具体答案.
All other questions and their answers provide the required facts and knowledge that leaves a lot to be done by the reader. This question aims at asking the specific answer to specific scenarios.
推荐答案
简单:
git config core.autocrlf false
(适用于所有和任何场景)
core.autocrlf
是一个 config,这意味着它不会与 repo 一起推送或克隆:它必须由用户设置.
core.autocrlf
is a config, which means it is not pushed or cloned with the repo: it has to be set by the user.
这是在回购级别处理 eol 的传统方式.
It was the legacy way to handle eol at the repo level.
您想要使用(根据您的场景添加或修改)是 gitattributes core.eol
指令.
What you want to use (add or modify depending on your scenario) are gitattributes core.eol
directives.
.gitattributes
是一个文件,可以在git repo 像任何其他文件一样.一旦您就 eol 政策达成一致,该政策将在每个克隆中强制执行.- 您可以根据需要为一个文件或一组文件设置
core.eol
指令(而不是全局存储库范围的配置core.autocrlf
)
.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 configcore.autocrlf
)
对于异构环境,core.eol(仅适用于您认为有问题的文件)应该是 native
(如果您怀疑您的编辑器坚持使用系统 eol 而不是使用已经存在的文件).
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".
这篇关于根据用例正确设置 git autocrlf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!