【发布时间】:2014-02-13 16:13:45
【问题描述】:
最近我在 .gitattributes 文件中发现了以下条目:
"* text=auto !eol"
!eol 是做什么的?
【问题讨论】:
-
eol = 行尾(似是而非的猜测)。
!eol很可能与 not 行尾有关。
标签: git line-endings eol gitattributes
最近我在 .gitattributes 文件中发现了以下条目:
"* text=auto !eol"
!eol 是做什么的?
【问题讨论】:
!eol 很可能与 not 行尾有关。
标签: git line-endings eol gitattributes
Git 有 2 个处理行尾的属性:
文档说:
此属性启用和控制行尾标准化。当一个文本文件被规范化时,它的行尾在存储库中被转换为 LF
这实际上意味着当你提交到 repo 时,它会将行尾转换为 LF
文档说:
此属性设置要在工作目录中使用的特定行尾样式。它可以在没有任何内容检查的情况下启用行尾规范化,从而有效地设置文本属性。
因此,虽然 text 属性会影响文件在 REPO 中的外观,但eol 会影响文件在工作目录中的外观。
现在,一个属性可以有 4 种状态:
设置没有值
例如:* text
未设置
例如:* -text
设置特定值
例如:* text=auto
未指定
例如:* !text
所以,* text=auto !eol 的意思是:
所有文件的属性 text 设置为 auto 和 eol 属性 unspecified。阅读文档我们发现 text=auto 意味着您让 git 决定文件是否为文本,如果是则将其规范化(将 repo 中的行尾设置为 LF)。
!eol 表示属性 eol 被显式设置为未指定。在这种情况下,它与根本不指定它相同,指示 Git 查看 core.eol 配置设置以了解如何处理工作目录中的行尾。请注意:
core.eol 配置变量控制 Git 将哪些行结尾用于工作目录中的规范化文件;默认是使用您平台的本地行结尾,如果设置了 core.autocrlf,则使用 CRLF。
但您会在以下情况下使用 !eol:
* text=auto eol=CRLF
test.txt !eol
基本上将 test.txt 的 eol 属性从 CRLF 覆盖到 unspecified。这意味着对于除 test.txt 之外的所有文件,Git 将在结帐时将 EOL 转换为 CRLF,但不会对 test.txt 执行任何操作。
【讨论】:
短版:
如果 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.
【讨论】:
* text=auto !eol
暗示:
【讨论】:
! 用于覆盖而不是用于否定。)
!eol仅适用于非文本文件的文件.
!eol 适用于非文本的文件?它与* 通配符在同一行,所以对我来说这意味着它正在删除eol 的显式设置,但不确定eol 的默认设置是什么。这将适用于所有文件,对吧?你的回答令人困惑。
text=auto 部分!
* 表示匹配所有文件,text=auto 表示根据操作系统相关的 EOL 处理文本文件,因此 !eol 适用于其余文件,即二进制文件。
它基本上根据documentation禁用eol:
有时您需要覆盖一个属性的设置 未指定状态的路径。这可以通过列出 以感叹号!为前缀的属性。
eol 执行以下操作:
此属性设置要在 在职的 目录。它可以在没有任何内容的情况下实现行尾标准化 检查,有效地设置文本属性。
【讨论】: