I see a lot of repositories with .gitattributes
files that normalise line endings with content like below:
*.js text eol=lf
Which should only normalise .js
text files, but they also explicitly exclude some binary files such as .png
files:
*.png -text
This doesn't seem necessary as the first rule is only applied to text-based .js
files. Is this correct? Or is this just considered best practice?
It's not entirely clear to me what your question is. The question I will answer is this: Is it necessary or advisable to mark particular files as text or binary, in .gitattributes
, when directing Git to perform CRLF line ending conversion?
The answer is: It is not necessary but it is advisable. In the absence of explicit advice, Git will guess, based on file contents (not file names or extensions, but a simple statistical analysis of byte-by-byte contents). Will Git guess that your jpg image is text, and thereby corrupt it? Will Git guess that your program source is binary, and therefore not bother to do CRLF line ending tweaking? I don't know, and neither do you.
Git's guesses are pretty darn good. But why take the risk, when listing your files explicitly is easy, and completely removes this risk?