A Guide to Branching in Mercurial

来源:互联网 发布:mysql share mode 编辑:程序博客网 时间:2024/05/22 17:25

原文地址:http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

 

Branching with Named Branches

The third way of branching is to use Mercurial’s named branches. Some people prefer this method (myself included) and many others don’t.

To create a new named branch:

$ cd ~/src/test-project$ hg branch feature

When you commit the newly created changeset will be on the same branch as its parent, unless you’ve usedhg branch to mark it as being on a different one.

Using a branch name to specify a revision is shorthand for “the tip changeset of this named branch”. In this example repository:

  • Running hg update default would update to changeset 3, which is the tip of  thedefault branch.
  • Running hg update feature would update to changeset 4, which is the tip of  thefeature branch.

In the past there was also the problem of not having a way to “close” a branch, which means that over time the list of branches could get huge. This was fixed in Mercurial 1.2 which introduced the--close-branch option forhg commit.

Mercurial will push/pull all branches by default, while git will push/pull only thecurrent branch.

This is important if you’re a git user working with Mercurial. If you want to push/pull only a single branch with Mercurial you can use the--rev option (-r for short) and specify the tip revision of the branch:

$ hg push --rev branchname$ hg push --rev bookmarkname$ hg push --rev 4

If you specify a revision, Mercurial will push that changeset and any ancestors of it that the target doesn’t already have.