问题
最近用windows,git push总是有一个问题,嫌麻烦,毕竟是自己写东西玩,直接通过 git push -f ,今天又出现了,烦人~
! [rejected] master -> master (non-fast-forward)
追踪
网上有人说:
git pull origin master --allow-unrelated-histories
git add ...
git commit ...
git push ...
执行git pull origin master --allow-unrelated-histories
这句话,把远程仓库和本地同步,消除差异
源自:https://blog.csdn.net/xieneng2004/article/details/81044371
但是并没有解决我的问题。
继续
git status
自己又git add 尝试了一次
warning: LF will be replaced by CRLF in .idea/workspace.xml.
The file will have its original line endings in your working directory
有一个警告,一看是警告就知道不处理也行,而这里提示的.idea/workspace.xml,正是上面报错得文件
网上查了查,大概意思就是windows的回车和换行符,在提交的时候转换成换行符,pull代码的时候再转换回来
通过git config --global core.autocrlf false
可以关闭这个功能,换来换去,什么鬼?我估计就是换来换去,给我搞坏了
源自:https://www.jianshu.com/p/450cd21b36a4
通过git config core.autocrlf
能够看自己有没有打开这个功能
果然
别人都只用git pull origin master --allow-unrelated-histories
就能解决,但是我还需要改一个这里git config --global core.autocrlf false
,不知道根本原因是不是这个,但是解决问题了,自己也成功push了,就不去纠结原因了。
解决
git pull origin master --allow-unrelated-histories
git config --global core.autocrlf false
git add .
git commit -m ""
git push origin master:master