How to revert a merge with Bazaar

With Bazaar, merges become easy but sometimes that leads to some issue.

Suppose you have a branch. You merge changes coming from another branch and you commit the changes. You test it and you decide that what you merge is not stable enough and you revert to the version previous to the merge.

Later on, you decide to try a new merge and that’s where the issue occurs.

Because Bazaar knows you have already merge the branch, the second merge will only be partial. It will not include the changes made before the first merge.

To do that, when you revert a merge, you neet to tell Bazaar to forget about the merge. The information below comes from https://answers.launchpad.net/bzr/+question/45980.

First tou need the sources you want to work with. Usually you will do that with a command like:

bzr revert -r X

X being the revision before the merge.

Then you need to uncommit the merge.

bzr uncommit -r X

X being the revision before the merge.

This does not change your working tree but will delete revisions older than X from the repository

If you do then:

bzr status

You will see the pending merge and you need to tell Bazaar to forget about the merge. To do that, just type:

bzr revert --forget-merge

This will not change your working tree but will remove any pending merge.

You can know commit your latest change and retry the merge later.

I think this was worth a post in the blog.

Comments are closed.