How do I undo a merge once it has been checked in?

Asked by TimeHorse

So, my repository is corrupted because I didn't know how to undo a commit (apparently it's bzr revert -r -2 and NOT bzr uncommit -r -2 -- who knew!?) and I just want to start from scratch as if the last 2 days had not happened, including having my repository forget that code was merged in from other branches. I want my repository to remember the last merge as being in June (the previous merge was in June) and only apply the differences since June to my reverted code. But I can't get bazaar to forget my checked-in merge history. --forget-merge does not work. HELP!

See also:

https://bugs.launchpad.net/bzr/+bug/273151

Question information

Language:
English Edit question
Status:
Answered
For:
Bazaar Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
John A Meinel (jameinel) said :
#1

Uncommit changes what has been committed to the branch, but it doesn't change the working tree. So the appropriate thing is "bzr uncommit -r -2; bzr revert" if you want to throw stuff away. Often you just want to slightly modify a commit, in which case "bzr uncommit; bzr add forgot_a_file; bzr commit" is what you want (as you don't want to get rid of your other changes, just fix a mistake in the commit.)

Which is why we don't automatically revert when you uncommit.

"--forget-merge" is not what you want. That is actually saying "forget the fact that this is merged". What you want is:

bzr merge -r revision_in_june ../otherbranch
bzr revert . # Revert the contents of all files and directories underneath here, but not the merged flag.
bzr commit -m "Null merge of 'otherbranch'"

Revision history for this message
TimeHorse (timehorse) said :
#2

I think you explained:

How do I apply the merge flag when I don't actually want to do a merge? That's actually pretty good advice, so thanks!

What I was trying to ask though, is say you merge your code with another branch, check that in, then accidentally delete a directory and accidentally check that in and then nïevely try to add the missing directory back via add then, realizing that this generates bogus diffs you try to undo but you observe there is no "undo" command so you uncommit the last two checkins instead but still get these bogus diffs so then you uncommit your merge and try to re-apply it but nothing happens so you uncommit the uncommit and get the almost perfect merge back but you still have the bogus diffs so you revert to a revision before the merge and now you still can't reapply your merge so you revert the merge back and still have the bogus diffs so you revert the merge away again and then manually apply the merges and your log messages are all bloodied and disgusting and you're not sure if you've forever ruined any chance of future merging with the same branches at a later date and you do have nice diffs but there is also code missing that should have been carried over with the diff and it's all so maddening and you just want to reset your repository back 2 days before all of this merge / delete / add / uncommit / revert NIGHTMARE began!

So, in summary, how do I restore my repository to a state pristinely prior to the merge and redo everything from scratch, preferably while not stopping the bogosity from entering the diffs but also with coherent log messages?

Thanks again for your consideration of my dilemma and take care.

Revision history for this message
John A Meinel (jameinel) said :
#3

I won't say that I completely follow your sequence of actions, but I would guess:

bzr uncommit -r REV_BEFORE_MERGE
bzr revert
bzr merge ...
bzr commit

Would get you back to where you want to be.

Can you help with this problem?

Provide an answer of your own, or ask TimeHorse for more information if necessary.

To post a message you must log in.