Batch convert text files from LF line endings to CRLF
Asked Answered
G

3

5

I have a vb.net (visual studio 2010) project that is version controlled with git (1.7.10.msysgit.1). I made a mistake of leaving core.autocrlf to true in git. Now I have set core.autocrlf to false, but the source code is already converted to LF line endings inside the repository. I want to change the line endings back to CRLF.

My plan to correct the situation is:

  1. git clone
  2. delete all source code files in the clone
  3. git checkout -f
  4. convert all LF to CRLF
  5. git commit
  6. git pull from the original repo

I am having problem with step 4. There are a lot of files in the project and hopefully there is a tool to batch convert all text files into CRLF line endings.

I have tried dos2unix that is available in the git bash, but looks like it will not process subfolders and it told me that the text files looks binary.

So, what is the best way to batch convert my source code back to CRLF line endings?

Gemini answered 9/5, 2012 at 11:1 Comment(0)
G
2

I missed the obvious way:

  1. git clone to folder A. git config core.autocrlf false
  2. git clone to folder B. git config core.autocrlf true
  3. delete all source files from folder B
  4. git checkout -f in folder B
  5. cut and paste all files and folders from folder B to folder A
  6. git commit in folder A
  7. git pull from the original repository
Gemini answered 9/5, 2012 at 11:34 Comment(0)
E
8

I took Endy's steps but reduced it to just using one single repository:

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"
Efficacy answered 30/5, 2012 at 12:18 Comment(1)
Nice! But be careful if you have ignored / untracked files.Gemini
G
2

I missed the obvious way:

  1. git clone to folder A. git config core.autocrlf false
  2. git clone to folder B. git config core.autocrlf true
  3. delete all source files from folder B
  4. git checkout -f in folder B
  5. cut and paste all files and folders from folder B to folder A
  6. git commit in folder A
  7. git pull from the original repository
Gemini answered 9/5, 2012 at 11:34 Comment(0)
G
2

Christoph's answer almost worked for us but for some reason git missed a bunch of files. (We're on version 2.20). We had to force git to rescan everything via "git read-tree --empty". After doing this, some files showed as "delete" which was incorrect, but after a reset and add that worked for us.

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"
Gettysburg answered 16/1, 2019 at 18:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.