Undo a wrong merge with Bazaar

Benoit Pierre benoit.pierre at gmail.com
Thu Jun 19 19:39:12 UTC 2014

On Thu, Jun 19, 2014 at 8:56 PM, TRIDENT JOB <trident_job at hotmail.com> wrote:
> Hi BZR community !


> I have an issue while using Bazaar and I would like to get the best
> practices to fix it. Here is the context:
> In the trunk of our project, one wrongly merged a branch (BranchA) in the
> trunk but he used revert on most files while keeping the merge info (so from
> bazaar BranchA was effectively merged in trunk, preventing to REALLY merge
> it later).
> The merged revision was committed as r4.
> After this (undesired) merge, many devs committed right after (r5 & r6).
> So my question is : how to undo this wrong merge ? (while keeping the
> commits after).
> I tried to uncommit back to r3 and merge each rev from r4 to R6 (omitting
> r4)
> I tried 'reverse cherry pick' r4 ... but the BranchA merge information may
> still memorized.
> trunk
>   |
>   r6
>   |
>   r5
>   |    branchA
>   |     |
>   r4 ---+
>   |     |
>   |    r2.2
>   |     |
>   r3   r2.1
>   |     |
>   r2 ---+
>   |
>   r1
> If you have a solution or some clue to fix it, please share it !
> (for example can REBASE command help here?)

I fear rewriting history is really the only solution here, which of
course mean that you must do it sooner rather than later since every
developer will have to overwrite its copy of the old branch with the
new one. If you are interested I have a personal plugin that I made
and used to use intensively (I don't use Bazaar anymore) that can make
it easier to interactively rewrite history (it's based on how "git
rebase -i" work): you can get it here:

With this plugin installed, you can (I assume you're using a
lightweight checkout, starting from trunk):

- make a backup copy: bzr branch . ../trunk.bak
- go back to r3: bzr pull --overwrite -r 3 .
- rewrite the missing history from backup: bzr rewrite ../trunk.bak

You can either keep r4 if there are some changes to keep (merge info
will be lost, so you will be able to merge branchA again), or just
remove it by deleting the corresponding line.


A: Because it destroys the flow of conversation.
Q: Why is top posting dumb?

More information about the bazaar mailing list