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

End*_*ono 4 git dos2unix

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

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

  1. git clone
  2. 删除克隆中的所有源代码文件
  3. git checkout -f
  4. 将所有LF转换为CRLF
  5. git commit
  6. git拉从原来的回购

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

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

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

Chr*_*oph 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"
Run Code Online (Sandbox Code Playgroud)

  • 太好了!但是如果您忽略/未跟踪文件,请小心. (2认同)

End*_*ono 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. git commit 在文件夹 A 中
  7. git 从原始存储库中拉取