在尝试为开发人员标准化平台时,我的需求之一是提交 .git/config
以便每个人都拥有相同的 CRLF 配置,而不会忘记手动设置它。
我该如何设置?
我有点担心所有这些针对 autocrlf
的消极情绪。如果它不起作用,为什么不删除此功能?要么这个功能的制作者被误解了,要么他们用它做了一个失败的实验,应该删除它以阻止更多的人浪费他们的时间(阅读晦涩的手册页,提出问题,人们回答这些问题等)。
最佳答案
我一直发现 autocrlf
配置属性有问题。
(如我的回答中所述 Git 1.6.4 beta on Windows (msysgit) - Unix or DOS line termination )
- 它不仅使some merges tricky
- 它可以变化depending on the shell used within one environment
- 它也有关于 git status 的问题
- 和 svn import .
备注:msysgit issue 538提倡默认将其设置为 false,而不是 true(这是当时 msysgit installer 设置的默认值——2010 年!),但我不相信。
我更喜欢以下三种解决方案之一:
- 配置一种行尾样式
- 使该配置通过不同的 Git 存储库传播
首先:git config --global core.autocrlf false
然后:
1.使用新的 config setting core.eol
(1.7.2+)
Sets the line ending type to use in the working directory for files that have the text property set.
Alternatives are 'lf
', 'crlf
' and 'native
', which uses the platform's native line ending.
The default value is native.
2。一个checkout/checking .gitattribute
.
参见 gitattributes手册页:
crlf
或 core.autocrlf
是在 .gitattributes
文件中记录以前本地配置属性的方法。
您可以添加 checkout/checkin attributes喜欢:
*.vcproj text eol=crlf
*.sh text eol=lf
3。一个git attribute filter driver这可以:
- 执行您可能想要设置的任何类型的格式标准
- 将这些标准应用于某些文件/目录
- 被记录为一个配置文件 (
.gitattributes
),可以被推送到任何地方。
关于git - 使用代码分发 git 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2333424/