move some commits to a new branch in Hg

我怕爱的太早我们不能终老 提交于 2019-12-12 03:31:11

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/14159849/move-some-commits-to-a-new-branch-in-hg

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!