git - 使用代码分发 git 配置

标签 git

在尝试为开发人员标准化平台时,我的需求之一是提交 .git/config 以便每个人都拥有相同的 CRLF 配置,而不会忘记手动设置它。

我该如何设置?

我有点担心所有这些针对 autocrlf 的消极情绪。如果它不起作用,为什么不删除此功能?要么这个功能的制作者被误解了,要么他们用它做了一个失败的实验,应该删除它以阻止更多的人浪费他们的时间(阅读晦涩的手册页,提出问题,人们回答这些问题等)。

最佳答案

我一直发现 autocrlf 配置属性有问题。 (如我的回答中所述 Git 1.6.4 beta on Windows (msysgit) - Unix or DOS line termination )

备注: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手册页: crlfcore.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/

相关文章:

git - 为什么 git rebase 重放功能分支提交一一?

git - 没有 git remove 删除文件。现在它在 repo 中,而不是本地的。如何从 repo 中删除?

git - VS 中的 TFS/GIT 无法切换到 master,因为有未提交的更改

git - 如何在 git pull 之前预览更改

git - 使用 GIT-TFS 工具将所有历史记录从 Azure DevOps TFVC 集合克隆到 Git 时出现 TF31002 错误

windows - git svn clone 已经运行了很长时间。有没有办法证明它没有陷入无限循环?

bash - git !alias 可以在 bash 和 Powershell 中使用

linux - Git 初始推送错误文件描述符错误

新的未暂存文件的 Git 警告

git 相当于 svnlook 的改变