2011-03-24 397 views
7

因此,我们已经得到了一个Git分支成一个棘手的状态:Git的合并,然后还原,然后还原的还原

两个分支:

* master 
* other_branch 

Last week someone accidentally merged other_branch (prematurely) onto master and pushed to origin. We noticed the error and I, in my naivete, committed

 
git revert bad_merge_commit 

to "fix" the problem. Everything looked ok, we moved on with our lives...

Today we attempted to merge master into other_branch as a step towards bringing other_branch into master. But my revert seems to have caused a nightmare. When master merges into other_branch, all (most?) of the work on other_branch is deleted. I presume this is because my revert instructs all the older commits to be reverted.

There are of course now many days' worth of commits on master on top of my revert, so untangling this looks like it may be difficult.

Is there some way to repair the damage? Can I perhaps reach in with some rebasing argument and delete the two offending commits?

Many thanks!

[Update - adding detail of current state as requested]

other_branch was branched off of master quite some time ago. Our standard practice is to merge master repeatedly into other_branch as we go to minimize buildup of conflicts (sometimes we rebase, but not in this case).

master commits A | B | C | BAD_MERGE [[email protected]] | REVERT_OF_BAD | D | E | F ... HEAD

other_branch commits P | Q | R | S [BAD_MERGE_FROM_HERE] | T | U | V ... HEAD

Attempt to merge master HEAD to other_branch HEAD causes problem.

Charles, I'm currently attempting a fix on a duplicate of master using the solution you suggested here: How to remove selected commit log entries from a Git repository while keeping their changes? .

[/Update]

+0

你能状态(最好带有挑逗性图片)到底是什么状态你现在在吗?修复它不应该太困难,但听起来您可能需要修复损坏,这会导致我的第一个(最近)尝试将'master'合并到'other_branch',如果这被提交并推送。 – 2011-03-24 07:46:04

回答

4

Yes, the problem is that the revert undid the changes introduced by the merge, but not merge itself. I think the addendum section of https://www.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.html describes a possible solution.

This document is also part of Git, under Debian you will find it at /usr/share/doc/git-doc/howto/revert-a-faulty-merge.txt

+0

谢谢,它看起来像这样描述我们的案例。我需要阅读和吸收。我会尽快回复。 :) – Wikiup 2011-03-24 15:53:02

+0

是的,这里描述的rebase --no-ff好像是关键。我们面前有一些工作,但我认为你已经指出了我的正确方向。谢谢! (这确实给我留下了后续问题:我应该做些什么来消除错误的合并并避免这种情况,同时铭记别人已经将它推到了原点?) – Wikiup 2011-03-24 18:30:41

+1

@cebewee链接没有工作了。 – Sfisioza 2011-11-30 08:52:20