git - *.bat text eol=crlf 但 git 仍然更改行结尾

标签 git powershell cygwin gitattributes

我正在运行 Windows 10,并在 Cygwin 命令行上使用 Cygwin 的 git,并在 VS Code、PowerShell 等应用程序中使用 Windows git。

我有一个 .gitattributes 文件,其中包含如下条目:

text eol=crlf

*.ahk     text eol=crlf
*.bat     text eol=crlf
*.cmd     text eol=crlf
*.css     text 
*.java    text 
*.js      text 
*.md      text eol=crlf
*.sh      text eol=lf
*.txt     text eol=crlf
*.xml     text

但是,我发现在 Cygwin 或 PowerShell 上交替运行 git status 会重复显示所有文件需要修改,具体取决于我上次检查它们的文件。我该如何获取两者同意并遵守我的 .gitattributes

回应@VonC的建议

2019 年 4 月 2 日星期二中午 12:32:15

在 Cygwin 上我这样做:

$ git config --global core.autocrlf
false

$ echo "* text=auto" >>.gitattributes

$ git add --renormalize .

$ git commit -m "Introduce end-of-line normalization"
... snip

$ git push
... snip

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

然后在 PowerShell 中

> git config --global core.autocrlf
false

> git status 
... snip.. every single file listed.. again!

最佳答案

确保在 Cygwin 环境中,git config core.autocrlf 设置为 false

git config --global core.autocrlf false

这样,Git 就不会自动更改文件 eol,并且会坚持其 .gitattributes 指令。

关于git - *.bat text eol=crlf 但 git 仍然更改行结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55446507/

相关文章:

linux - 无法从其中一台 Linux 服务器连接到 GIT 存储库

powershell - "The requested reader was not valid. The reader either does not exist or has expired"在SCOM中获取性能数据时出错

ruby-on-rails - 通过 cygwin 为 GITHUB 设置公钥/私钥

linux - 在cygwin中执行kinit时遇到 "fatal error - NtCreateEvent(lock): 0xC0000077"

git - 如何让 git 覆盖未发现的本地更改?

大文件的git配置设置

git - 为什么两次提交之间的 "git format-patch"与 "git diff"不同?

powershell - 使用 Powershell 对 CSV 文件进行排序

powershell - 使用 PowerShell 在 IIS FTP 站点上设置权限和设置

android - 使用cygwin交叉编译到arm-linux