简体   繁体   中英

How can I “split the branch further” in mercurial?

Admittedly a misleading title, but I didn't know how to put it better.

So I made the mistake of pushing all my project specific changes BEFORE I opened a branch. That way, there are some changeset sitting in the default branch that does not belong there. They should be in my newly opened branch.

Do I have to backout all the changesets first and then push them again to the correct branch? Does that even work?

Thank you for your help.

Without resorting to EditingHistory (which is generally advised agains, and is certainly in opposition to the mercurial "immutable history" design goals) those changes will be in your history forever. You can, however, undo them in your 'tip' revision and then trickle them back in multiple subsequent changesets spread over multiple branches.

Let's imagine this is your current history:

[R0] -> [R1] -> [R2] -> [R3]

Where revisions R2 and R3 have some stuff you wanted in the default branch and some stuff you wish was in a different branch. You can create a new revision, R4, that undoes R2 and R3. That can be done using backout as you suggest, or since you're doing multiple changesets, perhaps more easily using 'revert'.

hg update tip ; hg revert --all -r R2 ; hg commit -m 'undid changes R2 and R3'

then your history will look like this:

[R0] -> [R1] -> [R2] -> [R3] -> [R4]

then you can split your work into the changesets you wish you'd initially done, yielding a history like this:

[R0] -> [R1] -> [R2] -> [R3] -> [R4] -> [R5] -> [R7]
                                   \
                                    --> [R6] -> [R8]

R6 and R8 can be on the branch named 'default' or on a different named branch. Either way, you can push just R0 through R5 and R7 by doing:

hg push -r R7

That works because a push pushes a revision and all of its ancestors -- but R6 and R8 aren't ancestors of R7, so they won't get pushed no matter what branch they're on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM