LF will be replaced by CRLF in git - What is that and is it important

0 votes

I was trying to create a new rails application and when I do git init git add I am getting this LF warning.

Example:

The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in Gemfile.

The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in Gemfile.lock.

The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in README.

My question is, What's the difference between LF and CRLF? Should I ignore this?

May 16, 2022 in Others by Kichu
• 19,040 points
914 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

In Unix systems, the end of a line is represented with a line feed (LF). In windows, a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF).
You can turn off the warning by typing the following in the git command line:

git config core.autocrlf true

Here is a snippet for your reference:

Formatting and Whitespace

Formatting and whitespace issues are some of the more frustrating and subtle problems that many developers encounter when collaborating, especially cross-platform. It’s very easy for patches or other collaborated work to introduce subtle whitespace changes because editors silently introduce them, and if your files ever touch a Windows system, their line endings might be replaced. Git has a few configuration options to help with these issues.

core.autocrlf

If you’re programming on Windows and working with people who are not (or vice-versa), you’ll probably run into line-ending issues at some point. This is because Windows uses both a carriage-return character and a linefeed character for newlines in its files, whereas Mac and Linux systems use only the linefeed character. This is a subtle but incredibly annoying fact of cross-platform work; many editors on Windows silently replace existing LF-style line endings with CRLF, or insert both line-ending characters when the user hits the enter key.

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 filesystem. You can turn on this functionality with the core.autocrlf setting. If you’re on a Windows machine, set it to true – this converts LF endings into CRLF when you check out code:

$ git config --global core.autocrlf true

If you’re on a Linux or Mac system that uses LF line endings, then you don’t want Git to automatically convert them when you check out files; however, if a file with CRLF endings accidentally gets introduced, then you may want Git to fix it. You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input:

$ git config --global core.autocrlf input

This setup should leave you with CRLF endings in Windows checkouts, but LF endings on Mac and Linux systems and in the repository.

If you’re a Windows programmer doing a Windows-only project, then you can turn off this functionality, recording the carriage returns in the repository by setting the config value to false:

$ git config --global core.autocrlf false

I hope this makes some sense. 

answered May 17, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In Others

0 votes
1 answer

Windows git "warning: LF will be replaced by CRLF", is that warning tail backward?

 Depending on the editor you are using, ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
5,942 views
–2 votes
0 answers
0 votes
1 answer

What is Elastic IP in AWS and why it is useful?

A static public IPv4 address connected with ...READ MORE

answered Feb 8, 2022 in Others by Edureka
• 13,620 points
824 views
0 votes
2 answers

What is white box testing and how is it different from black box testing?

Black Box Testing is a software testing method in ...READ MORE

answered Feb 20, 2019 in Others by preetiagarwal
• 170 points
2,660 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,255 views
+2 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP