Windows(git smc client)上的Git拉不尊重.gitattributes的eol = lf [英] Git pull on Windows (git smc client) doesn't respect .gitattributes's eol=lf

查看:109
本文介绍了Windows(git smc client)上的Git拉不尊重.gitattributes的eol = lf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究最初是在Unix环境中开发的项目.

I am working on a project originally developed in Unix environment.

该项目有一个.gitattributes文件,该文件强制eol = lf超过标准crlf-lf转换

Such project has a .gitattributes file with forcing eol=lf over standard crlf-lf conversion

*.sh文本eol = lf

据我了解,这是告诉git保持原始LF行的结尾".

which is my understanding is telling git "keep the original LF line endings".

克隆此存储库时,在完成提取的瞬间,如果我执行 git status ,则某些文件被标记为已更改(特别是.sh文件)

When I clone this repository, in the moment the pull is complete, If I do git status, some files are marked as changed already (specifically .sh files)

git diff 显示

-FileContent
+FileContent

其中FileContent是文件中的所有文本.

where FileContent is all the text in the file.

我试图:

  • git reset --hard
  • git update-index-假定不变
  • git config --global core.autocrlf false
  • git config --global core.eol lf
  • 单个文件上的
  • dos2unix
  • 使用我的编辑器(Phpstorm)将特定文件的行尾更改为\ n

对这个问题没有影响.

我也尝试过:

  • git rm --cached -rf.->这删除了项目中的很多文件
  • 重新获取特定分支(git fetch; git checkout HEAD path/)
  • git add --renormalize.->所有.sh文件都显示为已修改(按照上述配置从分支中重新获取文件后,该文件仅为1)
  • git diff --ignore-all-space不显示任何内容
  • od path/file.sh 显示文件的二进制版本(在设置上述配置之前,实际上是文本)
  • git rm --cached -rf . -> this deleted a lot of files in the project
  • to re-fetch a specific branch ( `git fetch; git checkout HEAD path/)
  • git add --renormalize . -> all the .sh files appear as modified (it was only 1 after refetching the file from the branch following the above configuration)
  • git diff --ignore-all-space shows nothing
  • od path/file.sh shows a binary version of the file (before setting the above configuration was actually text)

如何让git尊重 .sh 文件的 eol = of 值?

How can I make git respect the eol=of value for .sh files?

编辑:通过 rm .git/index 删除索引并执行 git reset --hard HEAD 后,问题消失了

Edit: after removing the index via rm .git/index and performing git reset --hard HEAD, the problem was gone

也(供参考):没尝试-core.autocrlf为假

Also (for reference): didn't try - core.autocrlf to false

推荐答案

关于eol转换:

  1. 确保将core.autocrlf设置为false(这样,仅 [.gitattributes 指令] 1 将在播放)
  2. 使用 text eol = lf
  3. 接着执行 git add --renormalize.,以强制应用.gitattributes指令.(自Git 2.16起,,2018年第一季度)
  1. Make sure core.autocrlf is set to false (that way, only [.gitattributes directives]1 will be in play)
  2. Use text eol=lf
  3. Follows by git add --renormalize . to force the application of the .gitattributes directives. (since Git 2.16, Q1 2018)

通过 rm .git/index 删除索引并执行 git reset --hard HEAD 后,问题消失了

after removing the index via rm .git/index and performing git reset --hard HEAD, the problem was gone

这就是 git add --renormalize.应该模拟的.

这篇关于Windows(git smc client)上的Git拉不尊重.gitattributes的eol = lf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆