很遗憾没留下错误相关的代码截图,大家凑合看吧
git push 时报错
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@gitee.com:git_zn/jl.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
搜了很多资料 了解到是因为远程仓库的代码跟本地的不一样导致的,需要先执行pull命令将远程仓库的对应分支代码拉取下来再push(git相关命令我这里不作介绍了,可以直接去百度Git命令大全)
git pull <仓库别名,默认origin> <分支名> --allow-unrelated-histories
据说此时会有一个弹窗(小声BB我没有),如果有的话提示你修改一个文档的内容,不用管他,按ESC键
再按SHIFT+; (SHIFT+;用来输入一个冒号) 再输入wq保存
:wq
然后就可以push推送了
但是无奈拉取下来之后,本地的代码版本被迭代了
版本回退后再push还是报错
所以这个方法对我并不起作用
最后我是直接强制推送的代码,然后成功了
命令是 git push -f