Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix the line endings in checked out files after changing the autoclrf setting for a git repository?

I have cloned a git repository on Windows and noticed that the line endings are set to UNIX style (LF).

To fix it, I changed the repository's autocrlf value to true (core.autocrlf=true).

However, all of my checkout out files on disk are still have UNIX style (LF) line returns. How can I fix them?

like image 886
Dan Rigby Avatar asked Nov 20 '25 03:11

Dan Rigby


1 Answers

WARNING: Performing the below commands will cause you to lose any uncommitted changes.

To fix the line endings on your checked out files you will need to issue two commands:

  1. git rm --cached -r . This removes everything from git's index.
  2. git reset --hard HEAD This resets all local changes.

If you have pending changes, the task becomes much more difficult.

You can use the dos2unix command that comes with msysgit to try fix and the line endings on the files you're trying to commit.

Once you have managed to commit any changes you need to preserve, you can use the two above mentioned commands to reset the line endings for all the files in the respository.

like image 108
Dan Rigby Avatar answered Nov 21 '25 18:11

Dan Rigby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!