Igal Tabachnik
Igal Tabachnik

Reputation: 31548

Placing recent commits in a separate (named) branch in Mercurial (Hg)

If I have several commits made to the default branch since the last push, is it possible to go back, and move those commits into a separate named branch?

That is, I have:

A--B--C--D

and I want:

A
 \
  B--C--D

I hope this makes sense?

Upvotes: 4

Views: 94

Answers (2)

cdeszaq
cdeszaq

Reputation: 31280

If the commits are still in only your local repository and have not been pushed to any other one, then yes, you can re-arrange them with fairly minimal trouble. If they have moved beyond just your local repo, however, you will run into a lot of trouble.

To re-arrange commits, you want to use the MQ extension. Here's a tutorial, since it explains things better than I could here.

Upvotes: 2

jwd
jwd

Reputation: 11114

Take a look at the Transplant extension.

But personally, I'd do it using MQ, like so:

# assuming revs 1 and 2 are the ones we want to move
hg qimport -r1:2

# qimport creates a patch for each changeset
>hg qapplied
1.diff
2.diff

# pop the patches, to save for later
>hg qpop -a
popping 2.diff
popping 1.diff
patch queue now empty

# switch branches
>hg branch my-branch
marked working directory as branch my-branch

# push our saved changesets, essentially rebasing on the new branch
>hg qpush -a
applying 1.diff
applying 2.diff
now at: 2.diff

# make the patches part of permanent history
>hg qfin -a

You could probably also bend the Rebase extension to suit this purpose, if you prefer.

Upvotes: 5

Related Questions