共计 1291 个字符,预计需要花费 4 分钟才能阅读完成。
问题形容
问题如下图所示:
问题剖析
共事用的 mac(换行符为 LF), 自己用的 windows 零碎 (换行符为 CRLF), 代码仓库中的换行符为 LF. 在 git clone 过程, git 将所有文件换行符更换老本地换行符(CRLF) 了, 因而有了上图的报错.
解决办法
git config --global core.autocrlf false
git 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 \ / \
/ \ / \ / \