How can I cancel a merge in Mercurial and then retry with this branch?

I have two branches, default and branch1. By mistake, one person in our team combined branch1 with default. The content in branch1 is not yet ready for integration with the standard (it contains the main refinement of the assembly and deployment environment).

We conducted an experiment with "hg backout", supporting merging (not sure if this is the right way to do this). Then the changes from branch1 are deleted by default, which is good - but we cannot reuse branch1.

How do we solve this problem?

+48
version-control dvcs mercurial
Nov 11 '10 at 8:18
source share
6 answers

There are many scenarios here where you can do this, I will make each script a heading so that you can find a script that suits your case. Please note that I am still learning Mercurial, and I would like pointers, if what I say, is wrong, using the wrong terminology, could do better, etc.

No additional changes, the union is not divided (no taps / pulls)

The programmer merged, but did nothing, and does not have (and) that he shared the changes with anyone, in any way

In this case, just drop the local clone and get a new clone from safe storage.

Local changes on top of the merge, not general

The programmer merged and continued working on the basis of this merger. The changes that follow the merge must be saved, but the merge itself must be deleted. Changes (merge + next changes) were not transferred to anyone

In this case, I would do one of four:

  • Try using the REBASE extension, this will move the change sets from one place to another. If the changes are based on code changes that were entered with the merge, you must do manual work to reconcile the differences.
  • Try using the MQ extension to pull out the set of changes that should be stored in the patch queue, and then discard them elsewhere. This, however, will have the same problem as the REBASE extension in terms of merge-based changes
  • Try using the TRANSPLANT extension to “copy” changes from one place to another. However, the same problem exists as in the first two.
  • Repeat this work, perhaps with a sophisticated tool, to make changes to the change sets that I want to reset and repeat them in the right place.

To get rid of the merge changeset + of all the following changesets, there are several options:

  • Use the strip command in the MQ extension

    hg strip <hash of merge changeset> 
  • Clone and pull, and also specify the hash of the change sets that precede, but not include, the merge. In essence, create a new clone by pulling from a damaged clone into a new one and avoid pulling in a merge that you don't want.

     hg clone damaged -r <hash of first parent> . hg pull damaged -r <hash of second parent> 

Merging with others, clone control

The programmer clicked on the master repository or someone else, or someone pulled the programmers out of the repository. However, you (as in the development team) manage all the repositories, as you can chat and talk with everyone before you do more work.

In this case, I would see if it is possible to do step 1 or 2, but it can be done in many places, so it can require a lot of work.

If no one did the work based on a set of merge changes, I would use steps 1 or 2 to clear, then click on the master repository and ask everyone to get a new clone from the main repository.

Compression pressed, you have no clone control

The programmer clicked the merge, and you do not know who will have the set of merge changes. In other words, if you manage to eradicate it from your repositories , a wandering push from someone who still has it will return it.

Ignore the merge change set and work on the two branches as if that didn't happen. This will leave a drooping head. You can later later, when you merge the two branches, do a zero merge for this head to get rid of it.

  M <-- this is the one you want to disregard / \ * * | | * * | | 

Just keep working in two branches:

 | | * * | M | <-- this is the one you want to disregard |/ \| * * | | * * | | 

Then you combine the two, the real merge you want:

  m / \ * * | | * * | M | <-- this is the one you want to disregard |/ \| * * | | * * | | 

You can then perform a zero merge to get rid of a saggy head. Unfortunately, I do not know how to do this, except through TortoiseHg. It has a checkbox where I can discard changes from one of the branches.

With TortoiseHg, I upgrade to the merge that I want to save (upper, lowercase m), then select and right-click on the ragged merge head below, and then check the "Discard all changes from the merge target (other) edition": discard changes from target

+84
Nov 11 '10 at 8:40
source share

We conducted an experiment with "hg backout", supporting merging (not sure if this is the right way to do this). Then the changes from branch 1 are deleted by default, which is good, but we cannot regenerate using branch1.

I am using backup to cancel a merge. You cannot retry, but you can "merge the backup", i.e. When you want a remix, you do "hg backout" on "Backed out changeet ..." and then merge the branch again.

Example:

  7 M remerge 6 / \ 5 * | hg backout 3 (backout backout) 4 | * fix error 3 * | hg backout 2 2 M | fail merge / \ 1 * * | | 
+2
Mar 18 '15 at 2:05
source share

You cannot greatly compensate for the merger. IMO, the best way to handle this is to simply abandon the merge and continue the chain of change sets until the merge, leaving a hanging head (which can be split). If other changes have occurred since the merger, they can be reinstalled on a new “good” head.

0
Nov 11 '10 at 8:23
source share

This answer assumes you have already clicked

This will result in (at least one) unresolved head, depending on what you just forgot. More depending on who just popped from which branch.

I love HG and use it eagerly, but their idea of ​​a branch can drive someone butty in combination with a story that (by design) is intentionally immutable.

I usually clone a backup of the (locally) repo before doing branch merges for this reason. I always check before pulling.

Eric Raymond is working on something that is more or less agnostic of DVCS, which can (hopefully) help in situations like the ones you described, but I don’t think he will support HG for a full week or two. However, it might be worth a look.

But, only useful if no one pulled out the tip of the "ooopsie".

0
Nov 11 2018-10-11T00:
source share

Thank you all for your great contribution! Since we were in a hurry to solve the problem, and our group is relatively new to Mercurial, we used a very pragmatic solution.

On our repository server, we created a new repository, then cloned the old repository right up to the review just before the merge. Then he pushed a new clone to the server and sent a new link to everyone. Fortunately, we are a fairly small development team.

Maybe not the best way to solve the problem, but it worked :)

0
Nov 13 '10 at 17:50
source share

I had this exact problem. An employee accidentally merged my branch into a default branch while it was still incomplete. At first, I simply refused this merge, which seemed to work fine until I wanted to merge my branch into default for storage. The files that I need were marked for deletion during merge.

The solution was to completely revert to my original version, which fixed my colleague’s mistake and stepped back. This stopped the files marked as deleted, and let me successfully merge my default branch.

0
Apr 19 '12 at 4:13
source share



All Articles