Search code examples
linuxgitline-endingsgit-config

How to get Git to convert CRLF files to LF, on Linux?


I'm trying to do something very simple: check out a repo that has CRLF endings (and no .gitattributes) file, and end up with native (LF) line endings. I don't even want to commit back.

I've read Github's suggestion, and Tim Clem's article, but mostly they seem aimed at Windows developers.

I've tried this:

$ git config --global core.autocrlf=input
$ git clone https://github.com/DennisSchiefer/Project-OSRM-Web.git

But no - the file I care about, OSRM.Config.js, still has CRLF endings.

Trying core.autocrlf=true didn't help.

Even adding and committing a .gitattributes file (then git rm --cached -r . && git reset --hard) doesn't help.

I can't find any combination that will actually leave LF line endings on this file.


Solution

  • core.autocrlf will force git to process all text files.

    If OSRM.Config.js is not processed, that means Git deems it binary.
    See:

    Even with a .gitattributes with *.js text, that would still keep crlf.

    But with *.js eol=lf, that would actually force the conversion.

    See "Can git's .gitattributes treat all files as binary except a few exceptions?".