最近我在 .gitattributes 文件中发现了以下条目:
"* text=auto !eol"
做什么!eol
?
Git 有 2 个处理行尾的属性:
文档说:
此属性启用和控制行尾标准化。当一个文本文件被规范化时,它的行尾在存储库中被转换为 LF
这实际上意味着当您提交 repo 时,它会将行尾转换为 LF
eol
文档说:
此属性设置要在工作目录中使用的特定行尾样式。它无需任何内容检查即可启用行尾规范化,从而有效地设置文本属性。
因此,虽然text
属性会影响文件在 REPO 中的外观,但也会eol
影响文件在工作目录中的外观。
现在,一个属性可以有 4 种状态:
设置无值
示例:* text
未设置的
示例:* -text
设置特定值
示例:* text=auto
未指定的
示例:* !text
所以,* text=auto !eol
这意味着:
所有文件都将属性text
设置为auto
并且eol
属性未指定。阅读文档我们发现这text=auto
意味着您让 Git 决定文件是否为文本,如果是则将其规范化(将 repo 中的行尾设置为 LF)。
!eol
表示该属性eol
被显式设置为未指定。在这种情况下,它与根本不指定它相同,指示 Git 查看core.autocrlf
和core.eol
配置设置以了解如何处理工作目录中的行尾。请注意:
配置变量控制 Git将
core.eol
使用哪些行结尾来处理工作目录中的规范化文件;默认是使用您平台的本机行结尾,或者如果core.autocrlf
设置了 CRLF。
但是您会!eol
在以下情况下使用:
* text=auto eol=crlf
test.txt !eol
eol
基本上将属性从 CRLF覆盖为未指定的test.txt
. 这意味着对于除 之外的所有文件test.txt
,Git 将在结帐时将行尾转换为 CRLF。因为test.txt
Git 将遵循core.autocrlf
和core.eol
配置设置,因此在任何给定系统上,行尾可能是 LF 或 CRLF。
* text=auto !eol
暗示:
它基本上eol
根据文档禁用:
有时您需要覆盖未指定状态路径的属性设置。这可以通过列出以感叹号 ! 为前缀的属性名称来完成。
eol
执行以下操作:
此属性设置要在工作目录中使用的特定行尾样式。它无需任何内容检查即可启用行尾规范化,从而有效地设置文本属性。
精简版:
如果 Git 确定内容是文本,则在签入时将其行结尾规范化为 LF。还原某些嵌套的 .gitattributes 文件中的任何显式 eol 设置。
见man gitattributes
:
Each line in gitattributes file is of form:
pattern attr1 attr2 ...
Sometimes you would need to override an setting of an attribute for a path to
Unspecified state. This can be done by listing the name of the attribute
prefixed with an exclamation point !.
text
This attribute enables and controls end-of-line normalization. When a text
file is normalized, its line endings are converted to LF in the
repository. To control what line ending style is used in the working
directory, use the eol attribute for a single file and the core.eol
configuration variable for all text files.
Set to string value "auto"
When text is set to "auto", the path is marked for automatic
end-of-line normalization. If Git decides that the content is text,
its line endings are normalized to LF on checkin.
eol
This attribute sets a specific line-ending style to be used in the working
directory. It enables end-of-line normalization without any content
checks, effectively setting the text attribute.