git commit get fatal error “fatal: CRLF would be replaced by LF in”

前端 未结 9 1617
渐次进展
渐次进展 2020-11-29 16:10

I\'m using Ubuntu 13.10 x64, and I am working on a project that some developers are using Windows , I recently changed the git config core.eol to \"lf\" and

相关标签:
9条回答
  • 2020-11-29 16:43

    This is a classic issue:

    http://toub.es/sites/toub.es/files/styles/standard_article/public/field/image/firstcommit.png
    (picture from Luis Tubes's blog post)

    The usual fix is to convert those files yourself, with dos2unix or Swiss File Knife.

    I have always preferred to keep core.autocrlf to false, which means:

    git config --global core.autocrlf false
    
    0 讨论(0)
  • 2020-11-29 16:47

    I faced same trouble and fixed with editing .gitattributes as below.

    $ vim .gitattributes
    

    comment out 2 lines in .gitattributes

    -* text=auto
    -* text eol=lf
    +# * text=auto
    +# * text eol=lf
    
    0 讨论(0)
  • 2020-11-29 16:47

    I'm on a Mac using Terminal and had this problem with an .htaccess file I was trying to commit, getting the fatal error:

    fatal: CRLF would be replaced by LF in .htaccess
    

    I wanted to fix the problem, like the OP requests, not just turn off a git flag, so I found this article that gives a perl command to fix the problem on a per file basis.

    perl -pi -e 's/\r\n/\n/g' input.file
    

    So for my .htaccess error above, I ran the following:

    perl -pi -e 's/\r\n/\n/g' .htaccess 
    

    The flags -p, -i and -e (pie) can be combined to allow you to edit files using Perl from the command line. In this case replacing all \r\n found with \n.

    0 讨论(0)
提交回复
热议问题