【问题标题】:does a git repository have its own local value for core.autocrlf that overrides the global one?git 存储库是否有自己的 core.autocrlf 本地值来覆盖全局值?
【发布时间】:2012-09-02 15:43:16
【问题描述】:

根据this question,我了解 git 中的 core.autocrlf=true 会导致 CRLF 到 LF 的翻译。

但是当我输入: git config core.autocrlf

我明白了: 假的

但是,当我暂存已在 repo 中的已修改文件时,我仍然会收到以下警告:

Warning: CRLF will be replaced by LF in File1.X.
The file will have its original line endings in your working directory.

我的猜测是该文件的 repo 副本已设置为“autocrlf=true”。

问题:A. 我如何查询文件或 git repo 是否已经在强制 AutoCrlf? B. 如何关闭 autocrlf?

【问题讨论】:

  • 我想知道您是否可以拥有您不检查源代码控制的 .gitattributes 文件的“本地”副本?我希望有一些 repos 是“windows 风格”设置,只有 1 个 repo 是 LINUX 风格,而不强制该 repo 的所有用户使用 LINUX。这可能吗?
  • 你能加入一个只适用于本地特定目录(即 REPO)的 git 全局设置吗?我想要一些 repos 是 WINDOWS 和一些是 LINUX 风格的行尾?

标签: git core.autocrlf


【解决方案1】:

Git 允许您使用 .gitattributes 文件在每个存储库的基础上覆盖您的全局设置。您将它放在存储库的根目录中,并成为作为存储库的一部分提交的文件。我怀疑你的情况正在发生这种情况。

Github 上有一个很好的页面:https://help.github.com/articles/dealing-with-line-endings

简而言之,您可以使用 text 属性来设置特定文件扩展名的行尾。例如,将 sln 文件强制为 CRLF 将需要 .gitattributes 文件中的以下行:

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

【讨论】:

  • 对...所以...我会在.gitattributes 中添加什么,这将相当于我的全局配置中的core.autocrlf=false
  • 那么.gitattributes 中的以下内容是否等同于core.autocrlf=false* -text
  • 没有。如果您删除二进制文件,.gitattributes 也会影响合并能力。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-31
  • 2018-12-08
  • 2011-09-12
相关资源
最近更新 更多