首页 > 解决方案 > 如何在 gitlab 中撤消或恢复 git push?

问题描述

我不小心推了分支而不是主人。

那么有什么方法可以恢复推送,以便我可以带回主代码?我应该执行此命令以从 master 转到另一个分支:

git checkout ProductBranch

但不小心我执行了这个:

git push origin ProductBranch

标签: git

解决方案


"git push origin ProductBranch"

如果ProductBranch之前被推送,你可以强制推送它的最后一个状态:

git log ProductBranch
# make sure the history is the correct one, without your new commits
git push --force origin ProductBranch:ProductBranch

如果ProductBranch以前从未推送过,那么您可以考虑在远程端将其删除:

git push --delete origin ProductBranch

然后,只需切换到 master 并按下它:

git switch master
git push -u origin master

如果您已提交到错误的分支,您可以在 push 之前将这些提交修复回 master


推荐阅读