英文:
Reset line endings in the working directory when *enabling* core.autocrlf
问题
关于 core.autocrlf
和工作目录行尾字符的问题,当从索引中检出文件时,我看到一些奇怪的、不对称的行为。
当 禁用 auto-crlf 时,以下内容按预期工作:
git config core.autocrlf # true
git config core.eol # crlf
git clone <repo_url>
cd <repo>
git config core.autocrlf false
git checkout . # 从索引中更新了 N 个路径。
然而,相反的情况并不成立。以下操作不会重置行尾字符。
git config core.autocrlf # false
git config core.eol # crlf
git clone <repo_url>
cd <repo>
git config core.autocrlf true
git checkout . # 从索引中更新了 0 个路径
在启用的情况下,如何重置工作目录行尾字符?我没有看到这种不对称性的原因,这是否是一个错误?
英文:
Regarding core.autocrlf
and working directory line-endings, I am seeing some strange, asymmetrical behavior when checking out files from the index.
When disabling auto-crlf, the following works as expected:
git config core.autocrlf # true
git config core.eol # crlf
git clone <repo_url>
cd <repo>
git config core.autocrlf false
git checkout . # Updated N paths from the index.
However, the inverse is not true. The following does not reset line-endings.
git config core.autocrlf # false
git config core.eol # crlf
git clone <repo_url>
cd <repo>
git config core.autocrlf true
git checkout . # Updated 0 paths from the index
How can I reset working directory line endings in the enable case? Is there a reason for this asymmetry that I'm not seeing, or is this a bug?
答案1
得分: 1
对于"enable-case",您必须执行 git reset --hard
,而不是"disable-case",在那种情况下,您只需运行 git checkout .
。
英文:
For the enable-case, you must execute git reset --hard
, as opposed to the disable-case, where you can just run git checkout .
答案2
得分: 0
> 如我在"Git:如何在所有修订版本中重新规范化所有文件的行结尾?"中提到的,自Git 2.16(2018年第一季度)以来,您可以使用git add --renormalize .
(而不是git rm --cached -rf .; git add .
)
我建议仅使用.gitattributes
指令(如这里),并将core.autocrlf
保持为false
,正如我一直建议的。
英文:
> How can I reset working directory line endings in the enable case?
As I mentioned in "Git: how to renormalize line endings in all files in all revisions?", since Git 2.16 (Q1 2018), you would use git add --renormalize .
(instead of git rm --cached -rf .; git add .
)
I would recommend using .gitattributes
directives only (as in here), and keep core.autocrlf
to false
, as I have always recommended.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论