完整的错误提示如下:
To gitee.com:git_zn/jl.git
! [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.
根据错误提示 用git pull 将远程仓库的内容pull下来,无奈pull下来后再push还是报上述错误。
网上查找资料 找到了下面的解决办法。
在当前本地仓库下用git bash输入下面命令:
git pull gitee master --allow-unrelated-histories
这时候你本地和远程仓库中有冲突的代码会都在你本地,你把需要的变更的保存,其余的删除,然后再从远程pull后,再把你要更新的重新提交就可以了。