Git 包含 CRLF 和 LF 文件的存储库?

Git repository with both CRLF and LF files?

我有一个 git 存储库,其文件的行结尾在签出时应为 CRLF 或 LR,具体取决于特定文件。例如,我希望所有 *.sh 文件都以 LR 行结尾检出,而所有 *.bat 文件都以 CRLF 检出。

我一直在努力解决这个问题,但没有结果,接下来是我的 .gitattributes 文件:

* text=auto
#
# Declare files that will always have CRLF line endings on checkout.
#

*.sh text eol=LF

#
# Declare files that will always have LF line endings on checkout.
#

*.bat text eol=CRLF

#
# Denote all files that are truly binary and should not be modified.
#

*.zip binary
*.tar binary
*.exe binary
*.dll binary
*/dropbear binary
*update-binary binary

当我打开 .sh 文件或 .bat 文件时,两个行结尾都是 CRLF。我做错了什么?

注意:我在 Windows 电脑上开发。

编辑:系统、全局和本地配置

系统:

core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true

全球:

merge.tool=kdiff3
diff.guitool=kdiff3
core.editor="C:/Program Files (x86)/GitExtensions/GitExtensions.exe" fileeditor
core.autocrlf=true
credential.helper=!'C:\Users\XXXX\AppData\Roaming\GitCredStore\git-credential-winstore.exe'
user.name=xxxxx.xxxx
user.email=xxxx.xxxx@xxxxx.com
filter.lfs.clean=git-lfs clean %f
filter.lfs.smudge=git-lfs smudge %f
filter.lfs.required=true
push.default=matching

本地:

core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly
remote.origin.url=https://github.com/XXXXXX/xxxxxx.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.v2.10.0.remote=origin
branch.v2.10.0.merge=refs/heads/v2.10.0
branch.v2.10.1.remote=origin
branch.v2.10.1.merge=refs/heads/v2.10.1

此外,GitHub's documentation 声明如下:

Optionally, you can configure the way Git manages line endings on a per-repository basis by configuring a special .gitattributes file. This file is committed into the repository and overrides an individual's core.autocrlf setting, ensuring consistent behavior for all users, regardless of their Git settings.

编辑 2:

如果我将 core.autocrlf 设置为 false 并注释掉 .gitattributes 的所有行,那么 .sh.bat 文件都以 LF 行结尾打开.

eol 属性值与大多数 Git 一样,区分大小写。你想要:

*.sh eol=lf
*.bat eol=crlf