问题
I'm developing software under Linux which will be compiled using a Windows-only compiler. I want git to store my files with CR-LF line endings in the repository on Linux to be able to package the sources without changing them to Windows style.
My .gitattributes
looks like:
*.cpp eol=crlf
*.h eol=crlf
I also already tried core.eol = crlf
.
But git is still using LF line endings when I do checkouts and commits on Linux.
Is there any way to tell git using CR-LF on Linux?
回答1:
Does the windows only compiler get tripped up by lf-only line endings? If not, keep it set to false.
you need only to set auto crlf to true on a repo that will get the working tree set up for the compiler.
回答2:
I just tried this [Linux; git version 2.1.0] And as best as I can see its working with the following settings:
$ cat .gitattributes
.gitattributes text
.gitignore text
*.cpp text
*.h text
$ cat ~/.gitconfig
...
[core]
autocrlf = false
safecrlf = true
eol = crlf
In this configuration, git only allows crlf files into the database and gives a fatal error for lf on git add
.
Remove the safecrlf
setting and now git add
works but now you get a warning for lf-files.
Now rm
a checked-in file and reset --hard
gives a crlf file -- irrespective of whether it was checked in as lf or crlf.
I suspect: You have already checked in LF-files and now git is giving those.
Please try with the above settings on a new repo and let us know if it works.
来源:https://stackoverflow.com/questions/8833550/how-to-store-files-with-cr-lf-line-endings-in-git