.gitattributes在大多数Windows操作系统上均不受尊重

问题描述

因此,我尝试将.gitattributes文件引入我的项目存储库,但是遇到了一个问题,即在我的一些同等Windows 10计算机中不尊重该文件。我尝试查看Git pull on Windows (git smc client) doesn't respect .gitattributes's eol=lf和许多其他帖子都无济于事,因为它不符合我所看到的体验。我希望给定这个.gitattributes文件,所有文本都将保留为LF,但事实并非如此。 Windows操作系统正在将git add(已全部经过git add --renormalize .)上的文件转换为CRLF。确切的警告是:warning: LF will be replaced by CRLF in Callflows/ors_PostCreateOrsIssue.callflow. The file will have its original line endings in your working directory.

更令人困惑的是,在尊重LF和.gitattributes的情况下,我的几个同龄人的Windows操作系统按预期运行。

Gitattributes:

# Setting a default value and trusting git to do correctly determine files
*               text eol=LF

# Java sources
*.java          text diff=java
*.gradle        text diff=java
*.gradle.kts    text diff=java

# These files are text and should be normalized (Convert crlf => lf)
*.css           text diff=css
*.df            text
*.htm           text diff=html
*.html          text diff=html
*.js            text
*.jsp           text
*.jspf          text
*.jspx          text
*.properties    text
*.tld           text
*.tag           text
*.tagx          text
*.xml           text
*.grxml         text
*.callflow      text
*.json          text

# These files are binary and should be left untouched
# (binary is a macro for -text -diff)
*.class         binary
*.dll           binary
*.ear           binary
*.jar           binary
*.so            binary
*.war           binary
*.jks           binary
*.wav           binary
*.vox           binary
*.gram          binary

这是我的对等计算机上的有效设置。

  • git --version:2.18.0.windows.1
  • 使用git config -l检索的全局git配置。
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslcainfo=C:/Program Files/Git/asdf/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
user.name=asdf
user.email=asdf@asdf.com
difftool.sourcetree.cmd='' "$LOCAL" "$REMOTE"
mergetool.sourcetree.cmd=''
mergetool.sourcetree.trustexitcode=true

无法正常工作的同行中进行设置:

  • git --version:2.18.0.windows.1
  • git config -l
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
credential.helper=manager
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
filter.lfs.clean=git-lfs clean -- %f

任何帮助将不胜感激!

解决方法

您错误地配置了.gitattributes文件。该属性为eol=lf,而不是eol=LF。与大多数Git选项一样,此选项区分大小写,并且通过指定LF可以保留此属性。由于尚未设置,并且您的Git版本配置为core.autocrlf=true,因此您的文件被检出为CRLF。

如果您解决了该问题,则说明一切正常。