将推送的分支还原为具体的提交 [英] Revert pushed branch to a concrete commit

查看:161
本文介绍了将推送的分支还原为具体的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将dev分支(具有恒定的,有时是不稳定的更改)合并到我们的master分支(我们存储已发布的稳定代码)中.我想将master分支恢复到以前从未发生过的状态,例如从未与dev分支合并(并且在将来我们合并dev分支时,我们现在将丢弃的所有更改将再次合并").

I have merged a dev branch (with constant, sometimes unstable changes) to our master branch (where we store the released, stable code). I want to restore the master branch to the state it was before like the merge with the dev branch had never happened (and that when in the future we merge the dev branch all changes that we will discard now will be merged "again").

这是master分支的当前状态,我希望它在HEAD上具有'professional-1.1.2'提交/标记.

This is the current status of the master branch and I want it to have the 'professional-1.1.2' commit/tag at the HEAD.

我尝试过:

$ git revert -n professional-1.1.2..HEAD
fatal: Commit 9167e846a387c793edbc089c7ab6bd9eb8260456 is a merge but no -m option was given.
$ git revert -n -m 1 professional-1.1.2..HEAD
fatal: Mainline was specified but commit 380169097f35d07466640bc0db1b639278cd25fa is not a merge.
$ git revert -n -m 2 professional-1.1.2..HEAD
fatal: Mainline was specified but commit 380169097f35d07466640bc0db1b639278cd25fa is not a merge.

经过一些研究,我认为更好的选择是使用git reset --hard professional-1.1.2git push --force作为还原推送的git commit .其他开发人员在同一个办公室中,他们绝不应该提交任何内容来掌握(我也不应该这样做,但是...是的,我们没有每个分支的权限),因此告诉他们并进行任何操作都不是什么大问题需要采取行动.

After a bit of research I think that the better option is do a git reset --hard professional-1.1.2 and git push --force as the answer to Git: How to ignore fast forward and revert origin [branch] to earlier commit? or reverting push'd git commit . Other developers are in the same office, and they should never commit anything to master (as neither should I, but... yeah, we don't have permissions per branch), so it's not a big problem to tell them and do any action required.

最后,问题是:git revert somethinggit reset --hard <TAG>&& git push --force?如果是git revert,我应该使用哪个命令行?

So in the end the question is: git revert something or git reset --hard <TAG> && git push --force? If git revert, which commandline should I use?

推荐答案

-m number选项指定要还原为哪些父级(因为合并有多个父级).

The -m number option specifies which of the parents you want to revert to (since a merge has multiple parents).

所以您想要git revert -m 1 HEADgit revert -m 1 SHA_OF_MERGE_COMMIT(假设您做了git checkout master; git merge devel;)

So you want git revert -m 1 HEAD or git revert -m 1 SHA_OF_MERGE_COMMIT (assuming you did git checkout master; git merge devel;)

这篇关于将推送的分支还原为具体的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆