1

For a specific github repo ( only ) I need to make sure that all text files pushed have LF line-ending ( not CRLF ).

Further, pulled-down repo files should retain LF line-ending on clients either OSX or Windows.

Is this possible ?

Henke
  • 1,466
  • 2
  • 9
  • 22
BaltoStar
  • 6,511
  • 13
  • 46
  • 67

2 Answers2

1

Try to add a file named .gitattributes with the following contents:

*  eol=lf

to your repo. Then no matter what settings for core.autocrlf developers use, all the files will always use LF.

Just keep in mind, that it will change CRLF into LF upon commit in binary files also (like zip, jar, png, etc.).

Włodzimierz Gajda
  • 1,384
  • 11
  • 11
  • how to reconcile your answer with the answer above from nneonneo ? – BaltoStar Dec 17 '14 at 06:57
  • In my opinion the answer I gave is correct. With .gitattributes file the client's settings of core.autocrlf have no influence. – Włodzimierz Gajda Dec 17 '14 at 07:14
  • Ah, the fact that it will change `CRLF` to `LF` in binary files means that it will corrupt them, possibly silently. That's not desirable at all... – nneonneo Dec 17 '14 at 07:43
  • You'll need filename mask to avoid converting binaries: `*.txt eol=lf`, `*.css eol=lf`. Silently? With git you cannot change a file silently - all will be seen with `git status`. – Włodzimierz Gajda Dec 17 '14 at 07:53
  • Another useful way to avoid inadvertent conversion may be `some/dir/ binary` rule (to be placed in `gitattributes`). It denotes all the contents of a directory as binary. Git will not apply any new line conversion to files under `some/dir/`. – Włodzimierz Gajda Dec 17 '14 at 08:56
  • It will NOT necessarily convert line endings in binary files. Git has heuristics to automatically detect binary files. Whether those heuristics are good enough for you or not is another question http://stackoverflow.com/questions/6119956/how-to-determine-if-git-handles-a-file-as-binary-or-as-text See also https://help.github.com/articles/dealing-with-line-endings/ – Philip Daniels Dec 17 '14 at 10:11
  • Yes, git uses heuristics to qualify a file as text vs. binary. But these heuristics are turned off, when you use `eol` in `.gitattributes`. Here is an excerpt from `git help attributes`: *It enables end-of-line normalization without any content checks, effectively setting the text attribute.* – Włodzimierz Gajda Dec 17 '14 at 10:27
  • My bad...you are right Włodzimierz. Tested by inserting a CRLF pair into a PNG file then checking it in and cloning into a new directory. That's a bit shocking actually. – Philip Daniels Dec 17 '14 at 11:02
0

You can't really control what your clients do - if they have core.autocrlf set to true then LF will get translated to CRLF automatically.

If everyone uses core.autocrlf = input then it should all work fine.

nneonneo
  • 154,210
  • 32
  • 267
  • 343