Mercurial - backout an old merge

前端 未结 6 1639
礼貌的吻别
礼貌的吻别 2021-02-13 02:24

I have a branch that looks like this:

A->B->C->D->...->Z
     ^
1->2-^

where C is a merge from 2 an

6条回答
  •  甜味超标
    2021-02-13 03:10

    Use backout tool, but be aware of what you are doing:

    1. Update to the merge change set (C)
    2. Right click on that change set -> click Backout
      • After you do backout on branch, you don't need to commit it immediately. Better check before, if there (among changes that arose after chosing Backout option) aren't some changes from other branches that you don't want to back out. If so, uncheck them before commit.
    3. Click Commit
      • If you would merge branch 1-2 (or "numbered branch") into branch A-Z now (or later), you will lose all changes from "numbered branch" before changeset 2 (including) - that's what warning in @Marvin's answer is about.
      • To avoid that, you need to propagate this backout into "numbered branch" and redo backed out changes (later steps).
    4. If branch A-Z is not direct ancesstor of "numbered branch", then find first descendant branch between A-Z and 1-2 and update workbench to its tip.
    5. Right click on the latest revision in A-Z (= backout) -> click Merge with local
      • If there are more branches between A-Z and 1-2, repeat steps 4. and 5.
      • Don't merge anything into branch 1-2 yet.
      • Note: Always merge any branch only into the one from which it origins! Otherwise you risk losing some changes after future merges.
    6. Update to the tip of "numbered branch".
    7. Find all files (on filesystem) that were changed by backout and copy them to some temp directory.
    8. Right click on the latest revision of numbered branch's ancesstor -> click Merge with local
    9. Copy files from step #7 back to filesystem.
    10. Check changes in worbench and uncheck all changes, that are not from branch 1-2 (for example changes from revisions D - Z).
      • Unfortunately this has to be checked manualy. But it's the only safe way how to correct both branches.
    11. Click commit

    Tip: To be really sure what files were affected by any merge, right click on that revision and click Diff to parent

    This is basically scenario that we used today, when we find out that one branch (which was still in development) was accidentally merged into default (instead of another one, which had the same color in revisions graph :). (Both branches had pushed changes after this merge.) It might seems time-consuming, but still better than backout merge only and find numerous unexpected errors days (or weeks) later. (Own experience.)

提交回复
热议问题