创建 .gitattributes 文件后,Git 不会更改行结尾

标签 git newline

我想设置 git,以便将所有 LF 结尾更改为 CRLF。

我在我的存储库的根文件夹中创建了一个 .gitattributes 文件:

* text=auto 
# Have git change every .groovy and .java file to crlf
*.java eol=crlf
*.groovy eol=crlf

当提交一个我知道有 LF 结尾的 .java 文件时,我希望在 checkout 到新的本地分支时它会更改为 CRLF。但事实并非如此。有什么想法吗?

最佳答案

我相信您需要在“eol”属性之前指定“text”;所以你的例子将变成以下内容:

* text=auto 
# Have git change every .groovy and .java file to crlf
*.java text eol=crlf
*.groovy text eol=crlf

关于创建 .gitattributes 文件后,Git 不会更改行结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26401431/

相关文章:

git - 如何让 composer 不为包创建 .git 目录

java - Windows 和 Linux 之间的行尾不同吗?

excel - 无法使换行符在 XSLT 到 Excel 中工作

string - 在 C++ 中使用 String^ 添加新行

java - 用新行加入一个 json 字符串值

git merge 上游/master "already up-to-date"

git - 如何使用 Git 提交和推送更改

git 在 checkout 另一个分支时删除目录失败,目录名称前面有一个加号 "+"

android - 如何下载特定版本的 Android 源代码(例如 Android 2.2)

php - JavaScript 和包含\r 和/或\n 字符的字符串数组