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

前端 未结 9 1665
渐次进展
渐次进展 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: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.

提交回复
热议问题