为什么.gitattributes不能覆盖Linux上的core.autocrlf配置? [英] Why does .gitattributes not override core.autocrlf configuration on Linux?

查看:143
本文介绍了为什么.gitattributes不能覆盖Linux上的core.autocrlf配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为项目设置Git时,我注意到行尾规范化在Linux和Windows上有一些不同.

While setting up Git for a project, I've noticed that the line-ending normalization works a bit different on Linux and on Windows.

据我了解有关此主题的Git文档,Windows上的行为是正确的.具体来说,当存在.gitattributes文件时,该文件应覆盖core.autocrlf设置.

As I understand the Git documentation on this subject, the behavior on Windows is the correct one. Specifically, when a .gitattributes file is present, it should override the core.autocrlf setting.

下表显示了我所做的一些实验的结果.最左边的两列显示.gitattributes文件和core.autocrlf设置.其他列显示以下git命令的结果:

The following table shows the results of some experimentation I've done. The two left-most columns shows the .gitattributes file and the core.autocrlf setting. The other columns shows the result of the following git commands:

  1. git rm --cached <file>(强制执行下一个结帐以执行行规范化处理).
  2. git checkout HEAD -- <file>(检出文件,应用行末尾归一化)
  3. git ls-files --eol <file>(检查工作树中的行尾)
  1. git rm --cached <file> (force next checkout to perform line normalization handling).
  2. git checkout HEAD -- <file> (checkout the file, applying line ending normalization)
  3. git ls-files --eol <file> (check the line endings in the working tree)


+----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+
| .gitattributes | core.autocrlf | Linux 2.7.2 | Linux 2.11.0 | Linux 2.16.2 | Windows 2.12.2.windows.2 | Windows 2.16.1.windows.1 |
|                |               |             |              |              |                          |                          |
+----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+
| None           | true          | w/crlf      | w/crlf       | w/crlf       | w/crlf                   | w/crlf                   |
|                |               |             |              |              |                          |                          |
+----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+
| None           | false         | w/lf        | w/lf         | w/lf         | w/lf                     | w/lf                     |
|                |               |             |              |              |                          |                          |
+----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+
| * text=auto    | true          | w/crlf      | w/crlf       | w/crlf       | w/crlf                   | w/crlf                   |
|                |               |             |              |              |                          |                          |
+----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+
| * text=auto    | false         | w/lf        | w/lf         | w/lf         | w/crlf                   | w/crlf                   |
|                |               |             |              |              |                          |                          |
+----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+
| * text=auto    | true          | w/crlf      | w/crlf       | w/crlf       | w/crlf                   | w/crlf                   |
|   test text    |               |             |              |              |                          |                          |
|                |               |             |              |              |                          |                          |
+----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+
| * text=auto    | false         | w/lf        | w/lf         | w/lf         | w/crlf                   | w/crlf                   |
|   test text    |               |             |              |              |                          |                          |
|                |               |             |              |              |                          |                          |
+----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+

如您所见,在Linux上,即使存在.gitattributes文件,看来core.autocrlf设置仍然有效.

As you can see, on Linux, it seems that the core.autocrlfsettings has effect, even when a .gitattributesfile is present.

我需要一些帮助来确定这是否实际上是一个错误.

I'd like some help to determine whether this is actually a bug.

推荐答案

注意:.gitattributes文档已使用Git 2.21(2019年2月)进行了更新

Note: the .gitattributes documentation has been updated with Git 2.21 (Feb. 2019)

请参见提交c9446f0 杰夫·金(peff).
帮助方式: TortenBögershausen(tboegi).
(由 Junio C Hamano-gitster-

See commit c9446f0, commit 2b68085 (29 Jan 2019) by Jeff King (peff).
Helped-by: Torsten Bögershausen (tboegi).
(Merged by Junio C Hamano -- gitster -- in commit 13e2630, 07 Feb 2019)

doc/gitattributes:澄清"autocrlf覆盖eol"

仅当core.autocrlf设置为core.autocrlf时,我们才用core.autocrlf覆盖core.eol 除"false"外的其他内容.
让我们更清楚地说明这一点,并向读者指出git-config定义,该定义将对此进行更详细的讨论.

doc/gitattributes: clarify "autocrlf overrides eol"

We only override core.eol with core.autocrlf when the latter is set to something besides "false".
Let's make this more clear, and point the reader to the git-config definitions, which discuss this in more detail.

请注意,将core.autocrlf设置为trueinput会覆盖 core.eol(请参阅git-config中这些选项的定义).

Note that setting core.autocrlf to true or input overrides core.eol (see the definitions of those options in git-config).

这又回到了 Mark Adelsberger core.eol配置.
但这在Git 2.21中已经改变:

And that refers back to Mark Adelsberger's answer regarding core.eol config.
But this has changed with Git 2.21:

docs/config:在core.eol

中阐明文本属性"

docs/config: clarify "text property" in core.eol

`core.eol`:

设置行尾类型以在工作目录中用于以下文件: 当core.autocrlf为假时,设置了text属性
标记为文本(通过设置text属性或通过text=auto和Git自动将内容检测为文本).

Sets the line ending type to use in the working directory for files that are
have the text property set when core.autocrlf is false
marked as text (either by having the text attribute set, or by having text=auto and Git auto-detecting the contents as text).

替代方案是'lf','crlf'和'native',它们使用平台的本机行结尾.
默认值为native.
有关行尾转换的更多信息,请参见gitattributes.
请注意,如果core.autocrlf设置为trueinput,则将忽略此值.

Alternatives are 'lf', 'crlf' and 'native', which uses the platform's native line ending.
The default value is native.
See gitattributes for more information on end-of-line conversion.
Note that this value is ignored if core.autocrlf is set to true or input.

这篇关于为什么.gitattributes不能覆盖Linux上的core.autocrlf配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆