DarkDust
DarkDust

Reputation: 92424

Move branch start in Mercurial

My problem is similar to Mercurial move changes to a new branch, but is not exactly the same.

A colleague of mine started working on a new feature and issued a few local commits. Then he noticed "Oh well, that should go into a named branch" and thus created one. The problem is, the commits before should have been in that branch already. So the simplified history now looks a little like this:

O 7: default
|
O 6: default
|
|  O 5: newbranch
|  |
|  O 4: default
|  |
|  O 3: default
| /
O 2: default
|
O 1: default

So default now has two open heads: 7 and 4. I'd like to get rid of the open head 4 but of course still have 3 and 4 merged back into the "main" default later on when we merge newbranch back into main (merging them now is undesired as it would bring changes into default that we don't want there yet).

The question is: what's the best way to handle this ?

Do a --close-branch on 5, create a new branch off 2 and re-apply revisions 3-5 ?

As far as I've understood there's no good way to simply say "newbranch started at 3 instead of 5".

Update: Since this is has already been pulled by others I don't want to rebase the revisions in question. Forcing the colleague to recreate/switch branches would be OK since that would affect only one person instead of 5.

Upvotes: 3

Views: 728

Answers (1)

Tim Henigan
Tim Henigan

Reputation: 62238

To get rid of the extra default head, you could:

hg update -r 4
hg commit --close-branch -m "Closed extra default head.  The changes from this branch will be merged along with 'newbranch', once it is complete."

When you eventually merge newbranch, it will include revisions 3-5 plus any others that you commit on top of 5.

The only potential problem with this is that revisions 3-4 will not be labeled as part of the named branch. If this is really important for you, then you should close both the extra default head and the newbranch head and start over with a new branch rooted at revision 2.

Upvotes: 3

Related Questions