Solving Git LF will be replaced by CRLF

Solving Git LF will be replaced by CRLF

Git Jul 11, 2023

If you are using Window machine your new line is a character CR LF but for Mac and Linux is LF

This make git status show every file change. All files in repos are in red.

when you try to see the diff

warning: LF will be replaced by CRLF in index.js. The file will have its original line endings in your working directory.
What we want is only CRLF to make the code work on our Window workspace and LF elsewhere.

The fix is by use autocrlf

git config --global core.autocrlf true

You won’t see it work unless you delete and clone the repos again or restart the index by

git add --renormalize .

What does it do?

From the git document here.

“Git can handle this by auto-converting CRLF line endings into LF when you add a file to the index, and vice versa when it checks out code onto your file system.”

In short, when code enter your machine git add CR. When you add file by git, git strip off CR .

CODEMONDAY - Web App | Mobile App | Digital & IT Solution and Software Development Company
Realize your idea and ship it online. web application, website, mobile, Digital & IT Solution, desktop applications, e-commerce. Want your business to shine in the digital world? We are here to help.

Tags

TeamCMD

We are CODEMONDAY team and provide a variety of content about Business , technology, and Programming. Let's enjoy it with us.