这是我在我应该稳定的树枝上做的事情……

% 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分支恢复到原来的样子。

我该怎么办?


当前回答

如果您在共享回购中工作,那么公认的解决方案(来自@charles bailey)是非常危险的。

作为最佳实践,所有推送到共享远程回购的提交都应该被认为是“不可变的”。 使用'git revert'代替: http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#fixing-mistakes

https://git-scm.com/book/be/v2/Git-Basics-Undoing-Things

其他回答

一种不丢失你想要的更改的方法:

git reset cc4b63b 
git stash
git push -f origin alpha-0.3.0
git stash pop

然后您可以选择要推送的文件

另一种方法是:

创建另一个分支 使用“git Checkout”在该分支上签出之前的提交 推新树枝。 删除旧的分支并推送删除(使用git push origin——Delete <branch_name>) 将新分支重命名为旧分支 推动了。

git reset --hard HEAD^
git push origin -f

这将从您的本地设备以及Github中删除最后一次提交

如果您在共享回购中工作,那么公认的解决方案(来自@charles bailey)是非常危险的。

作为最佳实践,所有推送到共享远程回购的提交都应该被认为是“不可变的”。 使用'git revert'代替: http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#fixing-mistakes

https://git-scm.com/book/be/v2/Git-Basics-Undoing-Things

我相信你也可以这样做:

git checkout alpha-0.3.0
git reset --hard cc4b63bebb6
git push origin +alpha-0.3.0

这与最后一个方法非常相似,只是您不必在远程回购中浪费时间。