使用CRLF和LF文件的Git存储库?

Sto*_*oro 2 git newline lf line-endings core.autocrlf

我有一个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
Run Code Online (Sandbox Code Playgroud)

当我打开.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
Run Code Online (Sandbox Code Playgroud)

全球:

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
Run Code Online (Sandbox Code Playgroud)

本地:

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
Run Code Online (Sandbox Code Playgroud)

另外,GitHub的文档说明如下:

(可选)您可以通过配置特殊的.gitattributes文件来配置Git基于每个存储库管理行结尾的方式.此文件将提交到存储库并覆盖个人的core.autocrlf设置,从而确保所有用户的行为一致,无论其Git设置如何.

编辑2:

如果我设置core.autocrlffalse和评论的所有行.gitattributes,然后这两个.sh.bat文件使用LF行尾开.

Edw*_*son 7

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

*.sh eol=lf
*.bat eol=crlf
Run Code Online (Sandbox Code Playgroud)