我有一个 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 的文档指出以下内容:
或者,您可以通过配置一个特殊的 .gitattributes 文件来配置 Git 在每个存储库的基础上管理行尾的方式。该文件被提交到存储库并覆盖个人的 core.autocrlf 设置,确保所有用户的行为一致,无论他们的 Git 设置如何。
编辑2:
如果我设置core.autocrlf
并false
注释所有行,.gitattributes
则两者.sh
和.bat
文件都以 LF 行结尾打开。