I'm using Visual Studio code and have inherited a project that uses 'LF' line endings. By default Visual Studio Code opens my files in CRLF (i'm using Windows 10) which causes my git pre-commit hooks to fail. I don't get any error messages if I switch Visual Studio Code to use LF at the bottom right of the screen but obviously i'd like to avoid having to switch this every time I edit and try to commit a file.
I followed the instructions from this question and my understanding was that changing the files.eol setting to "\n" would open files in LF but it still opens them in CRLF.
I'm a little new to this stuff so please bear with me but if someone could tell me what i'm doing wrong that would be great.
Worth mentioning that the project has an editorconfig file with end_of_line setting as LF and changing this to CRLF also doesn't help
Note - Make sure you don't have any uncommitted changes else it will be deleted when you run the following cmd!
Run this in your terminal or cmd prompt
git config core.autocrlf false
git rm --cached -r .
git reset --hard
This usually happens when the project is created on UNIX based system & then used on a windows system because both have different line endings.
We need to disable auto CRLF on git & uncommit & recommit changes.
Reference
You can set the default end of line character in VSCode under File > Preferences > Settings > Files:Eol
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With