如何用合并后的提交还原合并提交? [英] How to revert a merge commit with a newer commit after it?

查看:90
本文介绍了如何用合并后的提交还原合并提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经知道如何还原合并提交,包括选择父项.
但是现在我面临另一种情况,在合并提交之后会有一个新的提交.

I already know how to revert a merge commit including selecting parents.
But now I'm facing a different situation where there is a new commit after the merge commit.

看着:

您可以看到在合并提交"2"之后,有一个新的提交"1".
我只想将"3"的合并还原为分支母版. (我知道"2"是合并提交).

You can see that after merge commit "2", there is a new commit "1".
All I want is to revert the merging of "3" to the branch master. ( I know that "2" is a merge commit).

问题:

如何使用红色箭头还原合并提交? 我已经对相对提交进行了编号,因此可以更轻松地引用答案.

How can I revert the merge commit with the red arrow? I've numbered the relative commits so it would be easier to ref in an answer.

推荐答案

我倾向于将Tower作为我的git客户端

I tend to use Tower as my git client here you can see me directly reverting an older commit.

首先在本地还原要删除的内容:

First revert the thing you want to get rid of locally:

 git revert sha-of-2 -m X

其中X是父编号(在这种情况下,可能是1). 有关详细信息,请参见此处.

Where X is the parent number (likely 1 in this case). See here for details.

解决由此产生的所有合并问题.解决这些潜在冲突将确保正确应用1,而不必首先还原它.然后提交并推送.

Resolve any merge issues that come from that. Resolving these potential conflicts will make sure that 1 is applied correctly without having to revert it first. then commit and push.

结果将是:

-- 4 -- 2 -- 1 -- '2 <- master
        /
-- 3 --/

其中'22的倒数.

警告:在重写历史记录后强行推入母版可能会对同一个分支的其他用户造成严重的负面影响.

WARNING: force pushing to master after rewriting history may have severe negative impact on other users of the same branch.

进行交互式变基:

 git rebase -i sha-of-2

删除合并提交,保留提交1,然后强制推送主控.

drop the merge commit, keep commit 1, then force push master.

结果将是:

-- 4 -- '1 <- master

-- 3

'1是一个新提交,其中原始更改为1,加上您已解决的所有冲突.

Where '1 is a new commit with the original changes of 1 plus any conflicts you had resolved.

警告:重写历史记录后强行推入主目录可能会对同一个分支的其他用户造成严重的负面影响.

WARNING: force pushing to master after rewriting history may have severe negative impact on other users of the same branch.

这可能更容易理解.它执行的功能与rebase示例完全相同,但是您无需自己进行rebase-fairy-dust,而是自己进行艰苦的工作.

This may be the easier to understand. It does the exact same thing as the rebase example able, but instead of applying rebase-fairy-dust, you do the hard work yourself.

您可以重新进行这些更改,而无需重新定级.重置为4,创建一个新分支,樱桃选择1,将母版重置为'1,然后强制按下.

Instead of rebasing you could re-do these changes yourself. Reset to 4, create a new branch, cherry pick 1, reset master to '1 and force push.

     /- '1 <- master
    /
-- 4 -- 2 -- 1
        /
-- 3 --/

git reset --hard sha-of-4
git checkout -B newmaster
git cherry-pick sha-of-1
# fix conflicts if any
git checkout master
git reset master --hard newmaster
git push --force

'11的精选版本.

这篇关于如何用合并后的提交还原合并提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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