Semmel
Semmel

Reputation: 2686

What's the difference between "* text=auto eol=lf" and "* text eol=lf" in .gitattributes?

This is very similar to this question: What is the differrence between `* text=auto` and `* text eol=lf` in .gitattributes?

But I'm specifically asking why I should use * text=auto eol=lf over * text eol=lf or vice versa?

From my understanding eol overrides the text setting, so what's the point in using the former? Is there a difference? If so - how?

I'm reading so many websites and Stack Overflow questions/answers right now - but I'm still utterly confused. Especially when I see this change: https://github.com/git/git/blob/master/Documentation/RelNotes/2.10.0.txt#L248

I find the phrasing of the change so hard to read that I'm now none the wiser. Can someone please shed some light on this?

Upvotes: 4

Views: 1603

Answers (1)

torek
torek

Reputation: 489838

Git has code in it to detect whether a file is text or binary.

If a file has a lot of zero (ASCII NUL) bytes in it towards the front, that file is deemed binary. The same goes for some other binary patterns.

Git uses this code, by default, to decide whether to show you a diff, when git diff detects some change in some file. If the file appears to be binary, Git says "binary files differ" (by default—you can make it print a usable diff, and git format-patch forces that behavior, for instance). Otherwise, the file appears to be text so yo uget a regular diff.

Git also uses this code for text=auto in .gitattributes, but not for text-without-=auto. So:

* text=auto eol=<whatever>

tells Git: Every time you extract the file from the index to the work-tree, apply the detection code to the file. If the detection code claims that the file is a text file, apply the end of line conversions while rehydrating the freeze-dried copy of the file from the index into the usable form in the work-tree. If the detection code claims that the file is binary, leave it alone.1

By contrast, * text eol=<whatever> tells Git: Every time you rehydrate the file into the work-tree, apply the end of line conversions. The bug in Git before version 2.10 was that * text=auto accidentally meant * text instead of * text=auto.


1Since the text-detection sometimes—though not all that often—misfires on (e.g.) .jpg image files, it's not wise to depend on text=auto. But it works most of the time.

Upvotes: 11

Related Questions