3

I know there is setting in .gitattributes to have

*.txt eol=lf

and there is also this to have all text files default to conversion:

* text=auto

However, when I tried to have all my text files as unix-line endings, I noticed this doesn't do anything:

* text=lf

And this changes also binaries:

* eol=lf

so how to have only text files and all text files with unix line ends?

EDIT: this can be done by setting core.eol setting. I was hoping to do it with just .gitattributes, is that possible?

eis
  • 51,991
  • 13
  • 150
  • 199

1 Answers1

2

Try this

* text=auto !eol

and set core.eol=lf in .git/config.

(the answer is edited, before I proposed one more option "* text=auto eol=lf" but it doesn't work for this case)

Dmitry Pavlenko
  • 8,530
  • 3
  • 30
  • 38
  • tried this, but it seems still that binaries get corrupted wheras without this line they are ok. Tested with an .exe file in windows environment. – eis May 24 '12 at 10:07
  • 1
    actually, second one seems to do it, but it requires core.eol to be set. So there is no way to do this with just .gitattributes? – eis May 24 '12 at 10:30
  • Git distinguishes between binary and text files by checking if first 8kb of the file contain a zero byte. Some binary files (like some PDF files) do not contain a zero byte. It's not very probable but maybe the same is true about your file? I'm pretty sure that the second option proposed should help (I'm a bit less confident about the first one). So maybe you're wrong in your experiments, mistyped something or use old Git version... I have no other idea. – Dmitry Pavlenko May 24 '12 at 10:33
  • Yes, I was wrong in that initially - second one works, first one doesn't seem to. – eis May 24 '12 at 10:35
  • Ok, I'll remove it from the answer. According to the documentation if you set "eol" attribute in .gitattributes explicitly this make Git consider all files of a specified pattern as text and forget "text=auto". So maybe this is why the first option doesn't work. So I think there's no one line solution. You may specify per-extension rules: "*.exe -text", "*.html eol=lf", "*.pdf -text" and so on.. – Dmitry Pavlenko May 24 '12 at 10:41
  • 1
    UPDATE: `* text=auto eol=lf` works for this since [Git 2.10](https://github.com/git/git/blob/master/Documentation/RelNotes/2.10.0.txt#L248). See https://stackoverflow.com/a/40977008/1009155 – David P Jun 13 '19 at 03:39