Davis Dimitriov
Davis Dimitriov

Reputation: 4257

Mercurial Getting out of a bad merge

I just merged branch A into B, and for some reason the merge did not go well. I want to revert B back to where it was before the merge and try again like it never happened before. I was thinking of just doing

hg clone myrepo newrepo -r A -r 12345

where 12345 is the revision number before B's bad merge commit

I think this works, but I have a lot of other branches (most of which are closed using commit --close-branch) and this puts those branches back to an inactive state.

Is there a way to clone everything except revision 123456 or something? (where 123456 is the bad commit on B)

Upvotes: 5

Views: 5146

Answers (4)

jkerian
jkerian

Reputation: 17056

It might not be as nice as hg rollback, but usually what I do is update to head A, merge in previous head B, check that I got it right this time, and then dummy-merge away the bad merge.

Upvotes: 2

Tim Henigan
Tim Henigan

Reputation: 62238

Assuming you have not pushed the merge changeset to any public location, the easiest solution is to use the hg strip command that comes with the Mercurial Queues (i.e. mq) extension.

From the wiki:

hg strip rev removes the rev revision and all its descendants from a repository. To remove an unwanted branch, you would specify the first revision specific to that branch. By default, hg strip will place a backup in the .hg/strip-backup/ directory. If strip turned out to be a bad idea, you can restore with hg unbundle .hg/strip-backup/filename.

Upvotes: 10

Lee
Lee

Reputation: 18767

Is it too late to use the hg rollback command? If so, try the hg backout command.

Upvotes: 1

Mark Drago
Mark Drago

Reputation: 2066

I hope I'm understanding your situation correctly. If I am you should be able to update to the revision of B before the merge, give that revision a new branch name, merge A in to it, and continue on. You'll probably want to mark the original B branch as closed.

$ hg up 12345  #12345 is the revision of B prior to the merge
$ hg branch B-take2
$ hg merge A
$ hg commit -m 'merge A in to B-take2'

$ hg up B
$ hg commit --close-branch -m 'mark original B branch as closed'

Upvotes: 1

Related Questions