这是我在我应该稳定的分支上所做的......

% git rebase master
First, rewinding head to replay your work on top of it...
Fast-forwarded alpha-0.3.0 to master.
% git status
# On branch alpha-0.3.0
# Your branch is ahead of 'origin/alpha-0.3.0' by 53 commits.
#
nothing to commit (working directory clean)
% git push
Fetching remote heads...
  refs/
  refs/heads/
  refs/tags/
  refs/remotes/
'refs/heads/master': up-to-date
updating 'refs/heads/alpha-0.3.0'
  from cc4b63bebb6e6dd04407f8788938244b78c50285
  to   83c9191dea88d146400853af5eb7555f252001b0
    done
'refs/heads/unstable': up-to-date
Updating remote server info

正如我后来意识到的那样,这完全是一个错误。我想撤消整个过程,并将 alpha-0.3.0 分支恢复到原来的样子。

我应该怎么办?

最佳答案

您需要确保此存储库的其他用户没有获取不正确的更改或尝试在要删除的提交之上构建,因为您将要回滚历史记录。

然后您需要“强制”推送旧引用。

git push -f origin last_known_good_commit:branch_name

或者在你的情况下
git push -f origin cc4b63bebb6:alpha-0.3.0

您可能在远程存储库上设置了 receive.denyNonFastForwards。如果是这种情况,您将收到包含短语 [remote rejected] 的错误。

在这种情况下,您必须删除并重新创建分支。
git push origin :alpha-0.3.0
git push origin cc4b63bebb6:refs/heads/alpha-0.3.0

如果这不起作用 - 也许是因为您设置了 receive.denyDeletes,那么您必须直接访问存储库。在远程存储库中,您必须执行类似于以下管道命令的操作。
git update-ref refs/heads/alpha-0.3.0 cc4b63bebb6 83c9191dea8

关于git - 撤消 'git push',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1270514/

10-13 09:33