0

We have a few work flows where we want to use git repositories mounted on NFS network shares. This generally works well, with the exception of line endings. Obviously, line endings on Linux and Windows differ, so a git status on the CentOS host may show no changes, and a git status in the same directory on Windows shows all files as modified.

Can any of the various git mechanisms to deal with line endings be configured to support this scenario ? We only want Unix-style line endings in our repos, of course, and we don't really care about the Windows SEEING the Unix line endings, but on occasion, a Windows tool will add or accidentally convert files, which we would then not want checked in with those endings.

Torque
  • 3,319
  • 2
  • 27
  • 39

1 Answers1

0

There are a couple possible solutions here. The best solution depends on whether you care about the endings in the working tree.

If you always want line endings in the repository to be LF, and you don't care about the working tree, you can set the following in the .gitattributes file in your repository (creating it if it doesn't exist):

* text=auto

That will make Git guess whether a given file is binary or text, and if it's text, it will perform conversion to the proper line endings when it's checked out. On Unix, the proper line endings will be LF, and on Windows, usually it will be CRLF (although you can use core.eol to override that).

If you always want line endings in both the objects and the working tree to be LF, then you need to do a little more work. You need to set each individual text file type appropriately with eol=lf:

*.c text eol=lf
*.h text eol=lf

The reason this is necessary is because eol=lf overrides text detection, which means it's not safe to apply to binary files, such as PDFs or JPEG files. If you applied it to all files in your repository, you'd corrupt any binary files that happened to contain a CRLF.

Regardless of which you do, you should do a git add --renormalize . and then a git commit. That will ensure that all of your files in the repository contain LF endings and they'll be checked out with the appropriate endings whenever Git checks them out. That doesn't prevent Windows tools from dirtying the repository with CRLF line endings, but if they do that by accident, only LF endings will be checked in.

bk2204
  • 64,793
  • 6
  • 84
  • 100