Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to abort a merge in mercurial?

I goofed up a merge. I'd like to revert then try again.
Is there a way to revert a merge before it is committed?

hg revert doesn't do what I'd like, it only reverts the text of the files. Mercurial aborts my second attempt at merging and complains original merge is still uncommitted.

Is there a way to undo a merge after an hg merge command but before it's committed?

like image 632
deft_code Avatar asked Oct 20 '10 18:10

deft_code


People also ask

What does hg rollback do?

If you want to revert just the latest commit use: hg strip --keep -r . Using strip will revert the state of your files to the specified commit but you will have them as pending changes, so you can apply them together with your file to a new commit.

How do you merge in mercurial?

To merge two branches, you pull their heads into the same repository, update to one of them and merge the other, and then commit the result once you're happy with the merge.

How do you use hg backout?

To backout a specific changeset use hg backout -r CHANGESET . This will prompt you directly with a request for the commit message to use in the backout. To revert a file to a specific changeset, use hg revert -r CHANGESET FILENAME . This will revert the file without committing it.


2 Answers

hg update -C <one of the two merge changesets>

like image 108
Omnifarious Avatar answered Oct 07 '22 16:10

Omnifarious


After you do hg merge, but before hg commit, your working copy has two parents: the first parent is the changeset you had updated to before the merge and the second parent is the changeset you are merging with. Mercurial will not let you do hg merge again as long as your working copy has two parents.

You have two options on how to proceed:

  1. If you want to abort the merge and get back to where you started, then do

    hg update -C . 

    This will update the working copy to match the first parent: the . always denotes the first parent of the working copy.

  2. If you want to re-merge some files then do

    hg resolve fileA fileB 

    This will re-launch the merge tools just as when you did hg merge. The resolve command is good if you find out at hg merge-time that your merge tools are configured badly: fix the configuration and run hg resolve --all. You can run hg resolve as many times as you want until you are satisfied with the merge.

like image 38
Martin Geisler Avatar answered Oct 07 '22 15:10

Martin Geisler