Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial Getting out of a bad merge

Tags:

mercurial

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)

like image 271
Davis Dimitriov Avatar asked Apr 29 '11 14:04

Davis Dimitriov


2 Answers

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.

like image 147
Tim Henigan Avatar answered Oct 03 '22 20:10

Tim Henigan


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.

like image 33
jkerian Avatar answered Oct 03 '22 20:10

jkerian