本文介绍了根据用例正确设置git autocrlf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找适用于某些用例的适当设置,但找不到任何描述相同的来源。因此,我问这个问题,作为任何寻找git autocrlf选项的正确设置的解决方案。



使用案例1:我在Mac上,其他开发人员都在Windows上。他们在加入之前管理源代码。



使用案例2:我在Windows上,其他开发人员都在Mac上。他们在加入之前管理源代码。



使用案例3:我在Linux上,其他开发人员都在Windows上。他们在加入之前管理源代码。



使用案例4:我在Windows上,其他开发人员都在Linux上。他们在加入之前管理源代码。



使用案例5:我在Linux上,其他开发人员都在Mac上。他们在加入之前管理源代码。



使用案例6:我在Mac上,其他开发人员都在Linux上。他们在加入之前管理源代码。



我应该使用什么样的git core.autocrlf设置?



编辑:
为什么这个问题不是重复许多类似的问题: 所有其他问题和他们的答案提供了所需的事实和知识,使读者有很多工作要做。这个问题旨在针对具体情况提出具体的答案。

解决方案

简单:

  git config core.autocrlf false 

(for all 任何场景)



core.autocrlf 是一个 config ,它意味着它不会被repo推入或克隆:它必须由用户设置。



这是在回购层面处理eol的传统方式。

p>

您要使用的内容(根据您的方案添加或修改)是gitattributes 。




  • ,它可以像任何其他文件一样在git repo中进行管理。一旦您同意采用eol策略,该策略将在每个克隆中执行。

  • 您可以将 core.eol 指令设置为文件或文件组(如果您需要的话)(而不是全局存储库范围的配置 core.autocrlf



对于异构环境,core.eol(仅适用于您认为有问题的文件)应该是 native (如果您怀疑编辑坚持使用系统eol而不是使用已存在于文件中的文件)。



更多信息,请参阅。


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.

Use Case 1: I am on Mac, the other developers are all on Windows. They are managing the source code before I joined in.

Use Case 2: I am on Windows, the other developers are all on Mac. They are managing the source code before I joined in.

Use Case 3: I am on Linux, the other developers are all on Windows. They are managing the source code before I joined in.

Use Case 4: I am on Windows, the other developers are all on linux. They are managing the source code before I joined in.

Use Case 5: I am on Linux, the other developers are all on Mac. They are managing the source code before I joined in.

Use Case 6: I am on Mac, the other developers are all on Linux. They are managing the source code before I joined in.

What setting of git core.autocrlf should I be using ?

EDIT:Why this question is not a duplicate to many similar questions:

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.

解决方案

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".

这篇关于根据用例正确设置git autocrlf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:33