【Git】push 分支报错 error: failed to push some refs to...

文章目录

报错消息

  • 示例代码:
➜ git:(test) git push origin test
 ! [rejected]          test -> test (fetch first)
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.
  • 翻译:
!(拒绝 ]           测试→首先测试(获取)
提示:更新被拒绝,因为远程包含您所做的工作
提示:没有本地。这通常是由另一个存储库推送引起的
提示:相同的ref。你可能想要首先集成远程更改
提示:(例如,'git pull…')然后再推。
提示:请参阅'git push—help'中的'Note about fast-forward '获取详细信息。

解决方法

分析:这是由于你push推送分支前,未进行pull拉取最新代码,导致版本不一致
解决:回退到合并之前的代码,pull拉取最新代码,再push推送分支

注意:这种解决方法适用于2个分支之间的merge操作,比如test分支回退版本,那test上合并的代码会丢失,等你test分支能成功pull后,需要重新merge开发分支上的代码合并到test上。所以记得保留这个版本的代码再回退到上一个版本,等pull成功,再重新合并代码

  • 查看最近2次提交的历史版本
➜  git:(test) git log -2			# 查看最近2次提交的历史版本
commit da20b931f4e04a61f0f9b4e4726a2e907e566fc6
Merge: 33df706e 6018c237
Author: 流星
Date:   Wed Jan 19 09:58:40 2022 +0800

    第二版

commit 6018c237278f5265e78314049d6642e493ebdb56
Author: 流星
Date:   Wed Jan 19 09:57:50 2022 +0800

    第一版

  • 回退到上一个版本
➜  git:(test) git reset --hard 6018c237278f5265e78314049d6642e493ebdb56
  • 再进行pull更新分支
➜  git:(test) git pull origin test
  • 重新合并当前分支
➜  git:(test) git merge dev
  • 最后再 push 上去
➜  git:(test) git push origin test

猜你喜欢

转载自blog.csdn.net/qq_45677671/article/details/122574511
今日推荐