How to store files with CR-LF line endings in git?

依然范特西╮ 提交于 2019-12-11 03:01:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!