oskarkv
oskarkv

Reputation: 2369

Total confusion about line endings

I'm on Windows. I have set my core.eol to native. I have set my core.autocrlf to false. I'm pretty sure I started out with files containing CRLF line endings, all of them being one of .clj, .md, or .gitignore. I committed them. Then in the next commit I committed the following .gitattributes

* text=auto

*.bat text
*.bib text
*.clj text
*.java text
*.md text
*.tex text
*.txt text

*.jpg binary
*.pdf binary
*.png binary

In that commit, the diff said every line of every file changed (the line endings I assume).

Having set core.eol to native, I thought I would get CRLF in my working tree, but that is not the case (only for the .gitattributes file, no other file, including .gitignore). I didn't notice earlier because I'm using Vim.

I thought the diff for the gitattributes commit looked ugly, so I tried setting different values for core.autocrlf and core.eol, for example setting them to true and crlf respectively, and doing git filter-branch --tree-filter HEAD. I got the error error: core.autocrlf=input conflicts with core.eol=crlf. I checked with git config --get core.autocrlf and that returned true. So why do I get the error?

I'm very confused. What I want is CRLF line endings in my working tree, and commits that don't change my line endings, i.e. they are LF when committed right from the start, and stay that way. How can I achieve that?

Upvotes: 0

Views: 782

Answers (2)

user456814
user456814

Reputation:

This very first line of your .gitattributes file:

* text=auto

basically ignores your setting for core.autocrlf and turns on line ending conversion for all users of your repository, including yourself.

If you don't want automatic line ending conversion, then you shouldn't use that setting in the .gitattributes file.

See Dealing with line endings and gitattributes Manual Page for more details.

Upvotes: 1

Zombo
Zombo

Reputation: 1

I am also on Windows. I use Git. My editor of choice is Notepad2

With this setup I have changed default line endings in Notepad2 to LF. As you can see I did not have to change Git EOL settings.

Now both locally and remotely my files use LF which feels simple and right.

Upvotes: 2

Related Questions