"!eol"是什么意思?
Git有两个属性与行尾处理有关:
文档说:
该属性启用和控制行尾标准化。当规范化文本文件时,其行尾在存储库中被转换为LF。
这实际上意味着当您提交到存储库时,它会将行尾转换为LF。
eol
文档说:
该属性设置要在工作目录中使用的特定行结尾样式。它启用行尾标准化而不进行任何内容检查,有效地设置了text属性。
因此,text
属性影响文件在存储库中的外观,eol
属性影响文件在工作目录中的外观。
现在,一个属性可以有4种状态:
未指定值:
例如:* text
未设置:
例如:* -text
具有特定值:
例如:* text = auto
未指定:
例如:*!text
因此,* text=auto !eol
表示:
所有文件的属性text
设置为auto
,eol
属性未指定。阅读文档,我们发现text=auto
意味着您让Git决定文件是否为文本文件,如果是,则将使其规范化(将行尾在存储库中设置为LF)。
!eol
表示将属性eol
明确设置为未指定。在这种情况下,它与不指定它是相同的,指示Git查看core.autocrlf
和core.eol
配置设置以查看如何处理工作目录中的行结尾。请注意以下内容:
core.eol
配置变量控制Git在您的工作目录中使用哪些行结尾标准化文件;默认情况下,使用本地平台的本机行结尾,或者如果设置了core.autocrlf
,则使用CRLF。
但是,在以下情况下,您将使用!eol
:
* text=auto eol=crlf
test.txt !eol
基本上是将test.txt
文件的eol
属性从CRLF覆盖为未指定。这意味着对于除test.txt
之外的所有文件,Git将在检出时将行尾转换为CRLF。对于test.txt
,Git将遵循core.autocrlf
和core.eol
配置设置,因此在任何给定系统上,行尾可能是LF或CRLF。
* text=auto !eol
含义:
!
是用于覆盖而不是否定。) - michas!eol
仅适用于__非__文本文件。 - devnulltext=auto
这一部分! - devnulltext=auto
会使通配符文件被 Git 自动识别为文本或二进制文件。然而,我不确定第二个属性(!eol
)如何影响每个文件。如果未设置 eol
,它是否也会自动确定文件是二进制还是非二进制,并适当地翻译行结尾呢?为什么不完全省略 !eol
(因为在我看来它的效果与不设置相同)? - void.pointer*
表示匹配所有文件,text=auto
表示根据操作系统相关的EOL处理文本文件,因此!eol
适用于剩余的即二进制文件。 - devnull根据文档,它基本上禁用了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.
!eol
很可能与“非行末”有关。 - Bleeding Fingers