Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: How to deal with one branch that has two heads

What if one branch has two heads? I came to this situation weeks ago for some reason I didn't merged them back then and just continued developing on one head. Now I want to get rid of the other head. What should I do? Should I just merge them after so many changesets?

like image 287
thoslin Avatar asked Aug 03 '11 14:08

thoslin


People also ask

How do you combine two mercurial heads?

To start a merge between the two heads, we use the hg merge command. We resolve the contents of hello. c This updates the working directory so that it contains changes from both heads, which is reflected in both the output of hg parents and the contents of hello.

How do I merge branches in Mercurial branch?

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 I change my branch on mercurial?

From the main menu, select Hg | Mercurial | Update to. In the Switch Working Directory dialog that opens, specify the target working directory: To switch to another line of development, choose Branch and select the desired branch from the list.

What is mercurial default branch?

Mercurial's main branch is called "default" and is analogous to "trunk" in SVN, "HEAD" in CVS, and "master" in Git. If you try to use some other name for your "main" branch, users will get a more or less random branch when they clone and commit things in the wrong place, which is generally undesirable.


1 Answers

So you have this:

o--o--o--A--B  <- older unnecessary head        \         1--2--3--4--5--6  <- newer ‘good’ head 

...and you don't need A and B, absolutely, 100% sure. If you aren't sure, and there are possibly salvageable things in A and B, better merge the heads to combine the changes. As Aaron said, Mercurial is good at it.

Now you have two options:

  • get rid of the old head, or
  • do a dummy merge of two heads that ignores head B.

If changesets A and B are present in other repositories you don't control, e.g. if other people pulled A and B into their repositories, or you pushed A and B to a public repository (say, Bitbucket), then you've released A and B into the wild, and can't get rid of them. You should do a dummy merge:

$ hg up 6 $ hg --config ui.merge=internal:local merge 

This will ignore any changes from A and B when merging.

If, on the other hand, A and B are private, you can either strip them:

$ hg strip A 

(Rev A and descendants stripped; enable the MQ extension to make strip available.)

Or, make a new clone of your repository without changesets A and B:

$ hg clone myrepo myrepo2-clone -r 6 

(Only rev 6 and ancestors added to the clone.)

like image 53
Helgi Avatar answered Sep 16 '22 22:09

Helgi