git trying to convert LF to CRLF on ubuntu with core.autocrlf set to true

I'm using git on ubuntu with autocrlf set to true. My editor is configured to use LF as end-of-line character. After I edited a file and did

git add .

I got :

warning: LF will be replaced by CRLF in file1.txt. (1)
The file will have its original line endings in your working directory. (2)

As to (1), why git would want to convert my LF in my file into CRLF? Should it work exactly the way around that only when your file contains CRLF and only then git will try to convert CRLF to LF?

As to (2), does that mean the file I'm looking at will still go with only LF but the snapshot in git's staging area is converted?

Answers


By looking at the warning message, I am guessing your configuration is the following:

  • You are using windows with core.eol set to native (default in git 1.7.2 and above) or have explicitly set core.eol to crlf
  • Your core.autocrlf is set to input

These git attributes, core.autocrlf and core.eol let you configure what you want for line endings and their possible values and what they mean is captured in the git man page and this stackoverflow answer

And the answer to both (1) and (2), your questions is, "Because you configured it so"

What you would rather want to do, also depends on what platform are you on, and what other platform would you access it in. It is recommended to let git store only LF (or CRLF in case of windows only use) as the end of line, as the blob hash generated would change otherwise and git would complain of "changed lines" even when thee change may be only of the line end characters. - Setting core.eol to lf and core.autocrlf to true or input on linux should take care of that.


Need Your Help

Matlab - How to improve efficiency of two port matrix calculations?

matlab matrix performance

I'm looking for a way to speed up some simple two port matrix calculations. See the below code example for what I'm doing currently. In essence, I create a [Nx1] frequency vector first. I then loop

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.