大多数 windows OS 不尊重 .gitattributes

.gitattributes not respected on most windows OS

所以我尝试将 .gitattributes 文件引入我的项目回购协议,但我 运行 遇到了一个问题,即我的一些同行不尊重该文件 Windows 10台机器。我试过查看 和许多其他帖子都无济于事,因为它不符合我所看到的体验。我希望给定此 .gitattributes 文件,所有文本都将保留为 LF,但事实并非如此。 windows OS 正在主动将 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.

更令人困惑的是,我的几个同行的 windows OS 在尊重 LF 和 .gitattributes 的情况下表现符合预期。

Git 属性:

# 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

这是来自我的同行机器的工作设置。

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

来自同行的设置不工作

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。

如果你解决了这个问题,事情应该会正常进行。