VSCode changing CRFL to LF on file save, and git records a change even if there is none
Asked Answered
K

3

6

I've noticed a weird behavior in VSCode, when I save a file, even if I don't make any change, I can see in the low right corner that it changes from CRLF to LF. Even if I make several changes, git tracks extra lines as being added and deleted at the same time.

I'm working on Windows, and so far I had no issue, it started happening just now. I've tried setting the global setting in VSCode for EOL to CRLF, and the Prettier extension also to CRLF (since I cannot disable it), but the issue remains.

I'm new at this, couldn't find similar issue online, just instructions how to set CRLF.

Kloof answered 6/3, 2020 at 8:57 Comment(0)
A
4

I had some problems like that, because I work in a team that have UNIX and Windows environments. I use Windows, but all files of the project was saved in repositorie as LF eol. In your case (Windows environment) you need garantee the default behavior of Git:

git config --global core.autocrlf true

With that, Git will try to change eol of files to CRLF in operation like (new branch, clone etc.). Even, you could try to add "files.eol": "\r\n" on your user/workspace settings on VSCode, then your IDE will user CRLF as default (new files, new lines).

Angelus answered 23/6, 2020 at 9:53 Comment(0)
B
1

If the project is based on Angular and you have installed 'Angular Essential' extension, please check settings of the 'EditorConfig' plugin which comes as a part of the extension. Some of the EditorConfig properties:

end_of_line (on save)
insert_final_newline (on save)
trim_trailing_whitespace (on save)

Barrens answered 18/1, 2023 at 13:40 Comment(0)
S
0

First, ensure the line endings settings on your vscode is set to crlf. If you want this as a global setting press ctr+shift+p and type user settings json and select the first option to open the global settings file. If you just want it on a specific project create a settings.json file inside a .vscode folder at the base of your project. Then add this line there.

    ...
    "files.eol": "\r\n"

This doesn't solve the problem though. after every pull or after launching vscode the changes still show up. Just running a git add . will show no more changes which I think is what is desired but you don't want to do this every time.

To solve this, you need a .editorconfig file at the base of your project. In it, you can add:

   [*]
   ...
   end_of_line = crlf

That should be it.

Sanhedrin answered 31/12, 2022 at 7:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.