问题形容

问题如下图所示:

问题剖析

共事用的mac(换行符为LF),自己用的windows零碎(换行符为CRLF), 代码仓库中的换行符为LF. 在git clone过程, git将所有文件换行符更换老本地换行符(CRLF)了, 因而有了上图的报错.

解决办法

git config --global core.autocrlf falsegit config --global core.eol lf

将git的autocrlf性能设置为false, 并把eol(end of line)设置为lf.

拓展

git config的官网介绍: https://git-scm.com/docs/git-...

咱们次要看这么几段内容就行了:

core.eol

Sets the line ending type to use in the working directory for files that are marked as text (either by having the text attribute set, or by having text=auto and Git auto-detecting the contents as text). Alternatives are lf, crlf and native, which uses the platform’s native line ending. The default value is native. See gitattributes[5] for more information on end-of-line conversion. Note that this value is ignored if core.autocrlf is set to true or input.

core.autocrlf
Setting this variable to "true" is the same as setting the text attribute to "auto" on all files and core.eol to "crlf". Set to true if you want to have CRLF line endings in your working directory and the repository has LF line endings. This variable can be set to input, in which case no output conversion is performed.

大略意思是:
1) core.eol有三个选项:lf, crlf, native, 特地要留神, 当core.autocrlf设置为true或input状况下, core.eol配置会被疏忽;
2) core.autocrlf有三个选项: true, false, input; 至于这三个选项的精确含意,官网上并没有明确写出, 我这里援用Stack Overflow上的一个高赞答复作为参考(https://stackoverflow.com/que...)

core.autocrlf=true:      core.autocrlf=input:     core.autocrlf=false:                                                     repo                     repo                     repo      ^      V                 ^      V                 ^      V     /        \               /        \               /        \crlf->lf    lf->crlf     crlf->lf       \             /          \         /            \           /            \           /            \