• Register
0 votes
4k views

Problem :

I am new to git. I am creating the new rails application but  warning in git about LF replacement. I do git init git add .

and then boom! I see this pop up for almost all files. I always face below warning usually if I build the application then it will disappears after doing many changes to files.

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.

I am unable to understand the message. How can I fix the message?

2.3k points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I had worked with GIT on both Windows and Unix system so I am familiar with the message which you have posted.

Generally in the Unix your end of a line is always represented with the line feed (LF). And in windows the line is always represented with the carriage return (CR) and your end of line (LF) thus (CRLF). So when you have code from git that was uploaded by the unix system then it will only have the LF.

If you want to turn warning off then you can do it by typing a below command in your git command line

git config core.autocrlf true
15.1k points
0 votes

Solution:

In Unix systems the end of a line is illustrated with a line feed (LF). In windows a line is illustrated with a carriage return (CR) and a line feed (LF) thus (CRLF). At the time you get code from git that was uploaded from a unix system they will just have an LF.

In case you are a single developer performing on a windows machine, and you don't care that git automatically replaces LFs to CRLFs, you can turn this warning off by typing the pursuing in the git command line

git config core.autocrlf true

In case you want to make an intelligent decision how git must handle this, read the documentation:

Formatting and Whitespace:

Formatting and whitespace problems are few of the more frustrating and subtle problems that many developers encounter at the time collaborating, particularly cross-platform. It’s very simple for patches or other collaborated perform to introduce subtle whitespace changes since editors silently introduce them, and in case your files ever touch a Windows system, their line endings might be replaced. Git has a few configuration options to help with these problems.

core.autocrlf

In case you’re programming on Windows and performing with people who are not (or vice-versa), you’ll possibly run into line-ending problems at some point. This is since Windows uses both a carriage-return character and a linefeed character for newlines in its files, on the contrary Mac and Linux systems employ just the linefeed character. This is a subtle however incredibly annoying fact of cross-platform work; many editors on Windows silently replace subsisting LF-style line endings with CRLF, or insert both line-ending characters at the time the user hits the enter key.

Git can handle this by auto-converting CRLF line endings into LF at the time you include a file to the index, and vice versa at the time it checks out code onto your filesystem. You can turn on this functionality with the core.autocrlf setting. In case you’re on a Windows machine, place it to true – this converts LF endings into CRLF at the time you check out code:

$ git config --global core.autocrlf true

In case you’re on a Linux or Mac system that applies LF line endings, then you don’t want Git to automatically convert them at the time you check out files; but, in case a file with CRLF endings suddenly gets introduced, then you may want Git to solve it. You can tell Git to convert CRLF to LF on commit however not the other way around by setting core.autocrlf to input:

$ git config --global core.autocrlf input

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

In case 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

 

31.7k points
edited by

Related questions

0 votes
1 answer 58 views
58 views
Problem: what is the meaning of this, and why this happened: the file will have its original line endings in your working directory.
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 10 views
10 views
Problem: I need someone’s help to fix it... the file will have its original line endings
asked Apr 2 Ifra 43.4k points
0 votes
1 answer 4 views
4 views
Question: The rmdir command automatically removes a directory and all of its subdirectories and files.
asked Jul 8 ArifulIslam 9.9k points
0 votes
1 answer 19 views
19 views
Problem: Where can I look for a solution to this problem : Unable to execute file in temporary directory?
asked May 28 Chi Omega 168k points
0 votes
1 answer 3 views
3 views
Question: In vi, using command mode, what ​series of key presses below will cause the line on which the cursor is on to be deleted?
asked Jul 7 LizzyM 4.5k points
0 votes
1 answer 22 views
22 views
Problem : Is there any way to rectify this problem: Cannot autolaunch dbus without x11 $display?
asked May 30 Sifat55 108k points
0 votes
1 answer 8 views
8 views
Question: What command can be issued to confirm what directory you are in at a command line prompt?
asked Jul 7 LizzyM 4.5k points
0 votes
1 answer 3 views
3 views
Problem: Git nothing to commit working directory clean
asked Jul 8 nila 121k points
0 votes
1 answer 41 views
41 views
Problem: I'm attempting to come up with a solution and would appreciate any assistance : Updates were rejected because the tip of your current branch is behind hint its remote counterpart?
asked Jun 10 Mezbah 130k points
0 votes
1 answer 57 views
57 views
Problem: Does anyone grasp the problem: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart?
asked Jun 10 Sawyer Parviz 168k points