5

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

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

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

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

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

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

4

3 回答 3

8

我采取了 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"
于 2012-05-30T12:18:04.373 回答
2

我错过了明显的方式:

  1. git clone 到文件夹 A. git config core.autocrlf false
  2. git clone 到文件夹 B. git config core.autocrlf true
  3. 从文件夹 B 中删除所有源文件
  4. 文件夹 B 中的 git checkout -f
  5. 将文件夹 B 中的所有文件和文件夹剪切并粘贴到文件夹 A
  6. 文件夹 A 中的 git 提交
  7. 从原始存储库 git pull
于 2012-05-09T11:34:37.417 回答
2

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"
于 2019-01-16T18:36:27.837 回答