Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected linebreaks to be 'LF' but found CRLF

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

like image 255
red house 87 Avatar asked Mar 09 '18 16:03

red house 87


2 Answers

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

like image 104
Rajendran Nadar Avatar answered Nov 13 '22 11:11

Rajendran Nadar


You can set the default end of line character in VSCode under File > Preferences > Settings > Files:Eol

like image 23
erica mitchell Avatar answered Nov 13 '22 13:11

erica mitchell