Update Git Config

Open file global config (E.g.: C:\Users\yourname\.gitconfig), add like below.

1. Force Git to use LF everywhere

[core]
  eol = lf
  autocrlf = input

2. Force Git to use CRLF everywhere

[core]
  eol = crlf
  autocrlf = false

3. In your git repository, open Git Bash and run these cmd one by one

git checkout-index --force --all
git rm --cached -r .
git reset --hard

4. That’s all.

Use Command Line

This is how to change git config setting via command line, use –global to make the changes the default.

An AutoCRLF setting of input means that when committing new files, CRLF will be changed to LF. To just leave things alone and commit as-is, use false.

git config core.eol lf
git config core.autocrlf input
git config --global core.eol lf
git config --global core.autocrlf input

Now make sure all local files are recreated with the correct line-endings:

git checkout-index --force --all

If there are still some files not reporting correct line-endings, remove everything from your local copy and update them:

git rm --cached -r .
git reset --hard

Converting from Windows-style to UNIX-style line endings

Change default setting on Visual Studio Code

Open Setting -> type “files.eol” in Search bar -> change to “/n”.

Convert line-ending for all files in a folder

Convert all files to LF:
find . -type f -exec dos2unix {} \;

Convert all files to CRLF:
find . -type f -exec unix2dos {} \;

You can exclude some folders, write like this:

Convert all files to LF:
find . -type d -name 'node_modules' -prune -o -type d -name '.sass-cache' -prune -o -type d -name '.git' -prune -o -type f -exec dos2unix {} \;

Convert all files to CRLF:
find . -type d -name 'node_modules' -prune -o -type d -name '.sass-cache' -prune -o -type d -name '.git' -prune -o -type f -exec unix2dos {} \;

Reference: https://support.nesi.org.nz/hc/en-gb/articles/218032857-Converting-from-Windows-style-to-UNIX-style-line-endings