将文本文件从 LF 行尾批量转换为 CRLF



我有一个 vb.net(Visual Studio 2010)项目,该项目由git(1.7.10.msysgit.1)进行版本控制。我犯了一个错误,在 git 中将core.autocrlf留给了 true。现在我已将core.autocrlf设置为 false,但源代码已经在存储库中转换为 LF 行结尾。我想将行尾改回 CRLF。

我纠正这种情况的计划是:

  1. git 克隆
  2. 删除克隆中的所有源代码文件
  3. git 结帐 -f
  4. 将所有低频转换为 CRLF
  5. git 提交
  6. 从原始存储库中提取 git

我在执行步骤 4 时遇到问题。项目中有很多文件,希望有一个工具可以将所有文本文件批量转换为 CRLF 行尾。

我已经尝试了 git bash 中可用的dos2unix,但看起来它不会处理子文件夹,它告诉我文本文件looks binary.

那么,将源代码批量转换回 CRLF 行尾的最佳方法是什么?

我采用了Endy的步骤,但将其简化为仅使用一个存储库:

1. git config core.autocrlf true
2. delete all files in your working tree (except the .git folder for sure)
3. git checkout -f
4. git config core.autocrlf false
5. git commit -am "corrected all line endings from LF to CRLF"

我错过了显而易见的方式:

  1. git clone to folder A. git config core.autocrlf false
  2. git clone to folder B. git config core.autocrlf true
  3. 从文件夹 B 中删除所有源文件
  4. 文件夹 B 中的 git 签出 -f
  5. 将所有文件和文件夹从文件夹 B 剪切并粘贴到文件夹 A
  6. 文件夹 A 中的 git 提交
  7. 从原始存储库拉取 git

Christoph 的回答几乎对我们有用,但由于某种原因,git 错过了一堆文件。(我们使用的是 2.20 版)。我们不得不强制 git 通过"git read-tree --empty"重新扫描所有内容。这样做后,一些文件显示为"删除",这是不正确的,但在重置和添加后对我们有用。

1. git config core.autocrlf true
2. delete all files in your working tree (except the .git folder for sure)
3. git checkout -f
4. git config core.autocrlf false
5. git read-tree --empty
6. git add .
7. git reset
8. git add .
9. git commit -m "corrected all line endings from LF to CRLF"

最新更新