git: How do I get rid of “warning: CRLF will be replaced by LF” without disabling safecrlf?

前端 未结 4 1341
情歌与酒
情歌与酒 2020-12-12 22:06

I\'m new to git, and I\'ve read a lot about line endings and how git treats them. I\'m on Windows by the way. I have made a .gitattributes file and set for exam

相关标签:
4条回答
  • 2020-12-12 22:19

    As far as I can tell, setting core.safecrlf to false is the only way to turn off that warning.

    safecrlf is generally not necessary if your attributes are set correctly. The point of safecrlf is to prevent normalization in a file that is supposed to have mixed (or non-LF) line endings in the repository. It's really only useful in combination with core.autocrlf (to make sure that its automatic guesses can't destroy anything), and if you're setting your own attributes via .gitattributes it should be okay to turn all that off.

    0 讨论(0)
  • 2020-12-12 22:26

    The short answer to your question is NO.

    Because, basically, core.safecrlf setting controls "warning level":

    • false - proceed without warning
    • warn - proceed with warning
    • true - don't proceed

    So, you have to choose option that suits you the most.

    0 讨论(0)
  • 2020-12-12 22:28

    use

    $ git config core.autocrlf false
    
    0 讨论(0)
  • 2020-12-12 22:30

    In your .gitattributes you can:

    # normalize text files to use lf
    text eol=lf
    
    # except these which we want crlf
    *.txt eol=crlf
    
    0 讨论(0)
提交回复
热议问题