Retroactive named branching in Mercurial

微笑、不失礼 提交于 2019-11-30 18:21:56

I just wanted to do this, and here’s the solution I found. A year has passed since the question was originally asked, this might explain why I can now find a solution. It has the disadvantage that you create an extra revision in the process, but this wasn’t too bad for me.

First, you go back to where you want to create the branch. In my case, I actually wanted to start a new root (because I wasn’t very sensible when I started the repository, but anyways), so I’m updating to null. You probably want to start somewhere else, it depends on your situation.

$ hg update null

Then, create the branch.

$ hg branch blah
$ hg commit -m "Created blah branch."

Then, we rebase all the commits we made onto our new branch:

$ hg rebase -s SOURCE -d DEST

The SOURCE here should be the first commit you made in the commits you want to create the branch from, and the DEST should be the commit where the branch was created (the one we committed above).

No, branch names are part of the changeset (it's really like a label you add to the commit), it means the changeset hash depens on the branch name.

So the only way to change it retroactively is by rewriting history (which doesn't play well if you pushed your changes elsewhere, since you'll have to rewrite every repo which has the changes).

To rewrite history, you could use for example mq.

Not a complete solution but, without re-writing history; you could tag the last change set in the unnamed branch. If you never rebranch from this the tag should surfice. If you do need to rebranch you can move on to a named branch after the tagged changeset.

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