简体   繁体   English

如何重新检出 Git 中的所有文件以从 CRLF 转换为 LF?

[英]How do I re-checkout all files in Git to convert from CRLF to LF?

I have files checked out with CRLF.我有使用 CRLF 检出的文件。 I changed git config --global core.autocrlf false .我改变了git config --global core.autocrlf false Git doesn't see any modifications. Git 没有看到任何修改。 When I edit a file, Git thinks the whole file changed.当我编辑一个文件时,Git 认为整个文件都发生了变化。 How do I re-checkout and overwrite all the files with LF instead of CRLF, so the diff works as expected?如何使用 LF 而不是 CRLF 重新签出并覆盖所有文件,以便差异按预期工作? I saw this but the answer referred to an invalid command.我看到了这个,但答案提到了一个无效的命令。 I saw this but it said "Git wants to commit files that you have not modified" which is not true.我看到了这个,但它说“Git 想要提交您尚未修改的文件”,这是不正确的。 I tried我试过

git pull --force
git checkout --force

However the files still have CRLF.但是这些文件仍然有 CRLF。 So how do I convert all the files from CRLF to LF?那么如何将所有文件从 CRLF 转换为 LF? I can edit each & every file in Notepad++ and use Edit > EOL Conversions > Unix (LF), which is what I've been doing on a file by file basis, but it's very tedious.我可以在 Notepad++ 中编辑每个文件,并使用 Edit > EOL Conversions > Unix (LF),这是我在逐个文件的基础上所做的,但它非常乏味。 There is probably an awk or sed script also, but I'm not familiar with them, and I'd prefer to only modify what is checked into Git, and not mess up .git/ .也可能有一个awksed脚本,但我不熟悉它们,我宁愿只修改签入 Git 的内容,而不是搞砸.git/


Also tried也试过

git reset --hard origin/master

And the files are still with CRLF!而且文件还在CRLF 中!


This is not a duplicate of the suggested duplicate because I don't want to commit anything.这不是建议的副本的副本,因为我不想提交任何内容。 Only want to fetch a fresh copy from Git.只想从 Git 获取一个新副本。 Also, Git doesn't see any files as being modified.此外,Git 没有看到任何文件被修改。

This seemed to work, but I'm not sure why.这似乎有效,但我不确定为什么。 It looks very scary with lots of changes, but it ended up not changing anything.它看起来非常可怕,有很多变化,但最终没有改变任何东西。 I got worried after the first line.第一行后我很担心。

git rm --cached -r .
git reset
git checkout .

No commits necessary.无需提交。

git add --renormalize . and then committing all changed files did it for me.然后提交所有更改的文件为我做了。

As per man git add it specifically mentions to run that after core.autocrlf change.根据man git add它特别提到在core.autocrlf更改后运行它。

--renormalize --重新归一化

Apply the "clean" process freshly to all tracked files to forcibly add them again to the index.对所有跟踪的文件重新应用“清理”过程,以将它们再次强行添加到索引中。 This is useful after changing core.autocrlf configuration or the text attribute in order to correct files added with wrong CRLF/LF line endings.这在更改 core.autocrlf 配置或文本属性以更正添加了错误 CRLF/LF 行结尾的文件后很有用。 This option implies -u.此选项意味着 -u。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM