撤消'git push' [英] Undoing a 'git push'
问题描述
这就是我在我的应该是稳定的分支上所做的...
$ b
%git rebase master
首先,倒带头重播你的作品...
快速转发alpha-0.3.0来掌握。
%git status
#在分支上alpha-0.3.0
#你的分支在53次提交之前超过'origin / alpha-0.3.0'。
#
无需提交(工作目录清理)
%git push
获取远程主管...
refs /
refs / heads /
refs / tags /
refs / remotes /
'refs / heads / master':最新
更新'refs / heads / alpha-0.3.0'
从cc4b63bebb6e6dd04407f8788938244b78c50285
到83c9191dea88d146400853af5eb7555f252001b0
完成$ b $ refs / heads / unstable':最新
更新远程服务器信息
我后来意识到这是一个错误。我想撤销整个过程,并将alpha-0.3.0分支恢复到原来的状态。
我应该怎么做?
您需要确保此存储库的其他用户不会获取不正确的更改或尝试在您想要删除的提交之上构建因为你即将倒回历史。
然后你需要'强制'推送旧的参考。 $ p> git push -f origin last_known_good_commit:branch_name
或者你的情况
git push -f原点cc4b63bebb6:alpha-0.3.0
您可能在远程存储库上设置了 receive.denyNonFastForwards
。如果是这种情况,那么你会得到一个错误,其中包括短语 [远程拒绝]
。
这种情况下,你将不得不删除并重新创建分支。
git push origin:alpha-0.3.0
git push origin cc4b63bebb6:refs / heads / alpha-0.3.0
如果这不起作用 - 也许是因为你有 receive.denyDeletes
set,那么你必须直接访问版本库。在远程存储库中,您必须执行类似下面的管道命令。
git update-ref refs / heads / alpha -0.3.0 cc4b63bebb6 83c9191dea8
Here's what I did on my supposed-to-be-stable branch...
% 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
That was all a mistake as I later realized. I'd like to undo this entire process, and revert the alpha-0.3.0 branch back to what it was.
What should I do?
You need to make sure that no other users of this repository are fetching the incorrect changes or trying to build on top of the commits that you want removed because you are about to rewind history.
Then you need to 'force' push the old reference.
git push -f origin last_known_good_commit:branch_name
or in your case
git push -f origin cc4b63bebb6:alpha-0.3.0
You may have receive.denyNonFastForwards
set on the remote repository. If this is the case, then you will get an error which includes the phrase [remote rejected]
.
In this scenario, you will have to delete and recreate the branch.
git push origin :alpha-0.3.0
git push origin cc4b63bebb6:refs/heads/alpha-0.3.0
If this doesn't work - perhaps because you have receive.denyDeletes
set, then you have to have direct access to the repository. In the remote repository, you then have to do something like the following plumbing command.
git update-ref refs/heads/alpha-0.3.0 cc4b63bebb6 83c9191dea8
这篇关于撤消'git push'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!