为什么eol = crlf在.gitattributes中不被认可

Rap*_*ert 4 git

因此,我决定在git repo中将所有具有Windows样式的行尾的文件转换为具有Unix样式的行尾。

我按照http://www.git-scm.com/docs/gitattributes#_end_of_line_conversion的说明进行操作:

echo "* text=auto" >>.gitattributes
rm .git/index     # Remove the index to force Git to
git reset         # re-scan the working directory
git status        # Show files that will be normalized
git add -u
git add .gitattributes
git commit -m "Introduce end-of-line normalization"
Run Code Online (Sandbox Code Playgroud)

后来我意识到,这也更改了* .bat文件,这些文件应保持为CRLF。我使用以下.gitattributes文件再次尝试了整个过程:

# Default 
*         text=auto eol=lf

# Windows-only files
*.bat     text eol=crlf
Run Code Online (Sandbox Code Playgroud)

这似乎并没有改变的输出git status,尽管批处理文件在我的工作副本中为CRLF,但仍被标记为“已更改”,.gitattributes并将其设置为完全相同。似乎git只会忽略与*.batgit show --raw还向我展示了文件现在是用LF而不是CRLF存储的。

Rap*_*ert 5

经过数小时的尝试(未能通过)找到关于格式的良好规范后,.gitattributes我决定尝试以下操作(请注意,这不是解决问题的正确方法):

*.bat     -text
Run Code Online (Sandbox Code Playgroud)

而且,瞧,批处理文件从中消失了git status,这表明文件的语法没有问题,就像我最初假设的那样。虽然我不想将批处理文件视为二进制文件,但这使我得出了我现在认为是正确的结论:

使用text属性标记文件时,我误会了git的实际作用。它始终在内部存储带有LF行结尾的文件,并且仅在结帐时转换为CRLF。因此,我的最初步骤是完全正确的,它们只是产生了输出,使我感到困惑,认为出现了问题。该文件已经实际改变; 以前它们与CRLF一起存储,但是现在它们仅与LF行尾一起存储,在结帐时会进行更正。