DEV Community

Discussion on: 🙏 Please Add .gitattributes To Your Git Repository

Collapse
 
mistval profile image
Randall

As a (mainly) Windows user I always disable autocrlf and standardize on LF because:

  1. If I'm building Docker images (and I often am), I don't want to be copying CR LF files into the Docker images. Some Linux utilities will choke on them.

  2. If my program reads, say, XML files, I don't want the (multiline) strings going through my code to differ depending on my OS, this has bit me before too.

  3. If I calculate a hash on a file I want it to be the same on any OS.

  4. While I have had problems with CR LF files on Linux, I have never had problems with LF files on Windows (I don't use Notepad).

Collapse
 
joepkockelkorn profile image
Joep Kockelkorn

@mistval Thanks for your comment, it got me thinking 😃.

For 1., isn't it wise to convert the line-endings to fit the target OS anyway? In your situation, if you want a Windows image in the future and copy over any files with LF endings, you will have the same problem.

For 2., this would also be solved if you take the solution from up above, convert the line-endings before running your code as a Docker container. But it depends on your use case as well: What are the files used for?; Who will use them in the future? etc.

For 3., if you use git hash-object to calculate the hash it will take into account the core.autoclrf or text=auto settings so the hash should be the same, even on a different OS.

You could also have issues on Windows by defaulting to LF for non-binary files like .bat.

Thread Thread
 
mistval profile image
Randall

Hi Joep, you have some good points. I suppose I just am rarely in situations where LF breaks things. I rarely run .bat files and I never build Windows images.

Ultimately it's ideal if repos have .gitattributes, if not, I've had a lot more luck with configuring git to default to LF than using autocrlf.