最近做一个项目,用了码云的代码仓库,前两天一直通过intellij idea端的git->add->commit->push进行push,然而今天一早再次使用这个进行版本控制时,却出现了如下提示:
Push rejected: Push to xxx/master was rejected
在网上查了说按Alt+F12,调出intellij 的terminal,然后依次输入git pull等三步,就能解决
但是到了我这里连git pull都是错的,然后回到项目所在文件夹,右键调出git bash,这次输入
git push --all project_name
提示如下错误:
Pushing to xxx.git
To xxx.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'xxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
后来想起来,是我早上在远程仓库上,手动修改了readme文件,这才导致远程和本地文件不一致
于是接下来用了最暴力的办法:
git push --all project_name -f
即强制覆盖远程仓库上的文件,其实在intellij 上,push时也有个force的选项,但在我这里一直是灰色的,无法点按,不知道是什么原因。
方法非常蠢,如果大家有更好的办法,可以留言一下哈~