<h2>近日使用“git add”出现如下错误:</h2>
$ git add . warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal', whose behaviour will change in Git 2.0 with respect to paths you removed. Paths like 'inc/jquery2.1.1/jquery.min.js' that are removed from your working tree are ignored with this version of Git. * 'git add --ignore-removal <pathspec>', which is the current default, ignores paths you removed from your working tree. * 'git add --all <pathspec>' will let you also record the removals. Run 'git status' to check the paths you removed from your working tree.
使用“git status”查看状态:
$ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: app/js/app.js new file: app/tpl/admin.html new file: app/tpl/home.html new file: inc/jquery.2.1.1/jquery.min.js modified: index.html Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) deleted: inc/jquery2.1.1/jquery.min.js
解决方法很简单:$ git add -A #或 git add -all
warning: Your console font probably doesn't support Unicode. If you experience strange characters in the output, consider switching to a TrueType font such as Lucida Console!解决办法:
$ git config --global core.autocrlf true
warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple
错误信息:warning: LF will be replaced by CRLF in XXXXXXXXXXXXXX.
解决办法:$ git config --global core.autocrlf false
事实上这并不会影响你push的结果,最终push还会成功,因为这只是一个”warning“
设置core.autocrlf=false
,windows也用LF换行
除了记事本,其他编辑器都可以正常编辑
如果设置core.autocrlf = false
,那么很可能会出现CRLF和LF混合的情况,这样会导致一些问题,例如git diff
失去功能,会发现很多行代码并没有修改,然而被认为是修改过了。
首先core.autocrlf = true
在windows上才是正确的选择,那么如何避免warning呢?还要有以下几个步骤:
添加.gitattributes
设置core.safecrlf = true
使用dos2unix、notepad++等工具来将LF转换成CRLF
相关阅读:
https://www.zhihu.com/question/50862500
https://xiaozhuanlan.com/topic/4053786912
你可以按照他说的那样运行:git config --global push.default matching
或者 git config --global push.default simple
命令,以后再push就不会有警告了。
下面说一下push.default matching和push.default simple的区别:
push.default设置maching的意思是:git push 会把你本地所有分支push到名称相对应的远程主机上。这意味着可能你会在不经意间push一些你原本没打算push的分支。push.default设置成simple的意思是:git push仅仅把当前所在分支push到从当初git pull pull下来的那个对应分支上,另外,这个过程也会同时检查各个分支的名称是否相对应。