为什么.gitattributes不能覆盖Linux上的core.autocrlf配置? [英] Why does .gitattributes not override core.autocrlf configuration on Linux?
问题描述
在为项目设置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:
-
git rm --cached <file>
(强制执行下一个结帐以执行行规范化处理). -
git checkout HEAD -- <file>
(检出文件,应用行末尾归一化) -
git ls-files --eol <file>
(检查工作树中的行尾)
git rm --cached <file>
(force next checkout to perform line normalization handling).git checkout HEAD -- <file>
(checkout the file, applying line ending normalization)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.autocrlf
settings has effect, even when a .gitattributes
file 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
overrideseol
"We only override
core.eol
withcore.autocrlf
when the latter is set to something besides "false
".
Let's make this more clear, and point the reader to thegit-config
definitions, which discuss this in more detail.
请注意,将core.autocrlf
设置为true
或input
会覆盖
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" incore.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
设置为true
或input
,则将忽略此值.
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屋!