When collaborating on software, a common problem that quickly becomes a major painpoint is the end of line of your files. If you’re working with people on different system OSs, this is going to happen.
Why is it a problem? It creates a lot of noise in otherwise sane commits.
It can also nearly destroy your local working tree if you have a different EOL setup than that of the committed files. This can make it next to impossible to find what’s actually changed in your local tree.
Solution
Now, of course you can just set your git’s eol mode.
Hell, you can define it based on filetype (which is useful for raw files like images).
But, there is only one solution that removes this problem without a shred of doubt: .gitattribute
files.
It’s the same thing, but defined per the repository, so you don’t have to trust that each user has set up their system to match your EOL.
Here’s a list of sample gitattribute files for various projects: gitattributes / gitattributes
As to which EOL is better, don’t ask me. Technically, CR or LF is shortest, as Window’s CRLF is two characters, but in the modern day it shouldn’t matter.
Sources
-
Here’s a post from someone much smarter than me: Mind the End of Your Line.
-
Here’s the GitHub documentation on the subject: Configuring Git to handle line endings
This is a nearly pointless post, but I’ve seen this happen too many times…