move some commits to a new branch in Hg

My repo is currently as follows:

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

I would like to move 6 and 7 to a new branch, how can I do it?

  • symbolic link to specific git reference
  • git branch with multiple upstreams
  • Github delete branch even after made commits to it?
  • How do I use Git's interactive rebase with a local-only repository (no remote / origin)?
  • Vendor Branches in Git
  • Configure TeamCity to build from SVN trunk, branches and/or tags
  • Must every git commit be an ancestor of a branch?
  • What files in an Xcode iOS project should I tell Mercurial to ignore?
  • git: on the server, divert pushes to one branch to another
  • Can't merge feature bookmark into master bookmark in mercurial
  • Difference between Revert and Update in Mercurial
  • revert back to last commit in git branch
  • 2 Solutions collect form web for “move some commits to a new branch in Hg”

    You can use the rebase extension for this. It needs to be enabled but that link has the information on how to do it.

    The commands would be:

    hg update 2
    hg branch newbranch
    hg commit -m "Creating new branch"
    hg rebase -s 6 -d 8
    

    This creates the new branch, commits it (which would create revision 8 in your example) and then moves revision 6 and its descendants onto the new branch. Obviously, you’d need to look up the actual revision numbers for your repository.

    You could also do it with the mq extension but I think that rebase is easier to use in this instance.

    Depends how you define the term “branch”. If you’re talking about named branches then Steve Kaye’s answer is fine.

    If you’re talking about a branch like 5 & 6 are on a branch in your diagram, then you don’t need to do anything. 6 & 7 are already on their own branch. You can leave them alone, and move back to revision 2 to continue work there.

    hg update 2
    <continue work>
    hg commit -m "New Stuff"
    

    That will leave you with a graph like this:

    o 8: default
    |  
    |  O 7: default
    |  |
    |  O 6: default
    |  |
    |  |  O 5: default
    |  |  |
    |  |  O 4: default
    |  |  |
    |  |  O 3: default
     \ | /
       O 2: default
       |
       O 1: default
    

    If you want to assign a name to each of those tips, take a look at bookmarks.

    hg bookmark -r 8 stable
    hg bookmark -r 7 experimental-stuff
    hg bookmark -r 5 some-feature
    

    … and then you can change between them by name.

    Git Baby is a git and github fan, let's start git clone.