Reputation: 110570
I would like to do some experimental work in a hg project. So I would like to create branch, commit to it. And if the experiment works, I can merge it back to main branch.
In git, I can do
$ git branch experimental
$ git checkout experimental
(edit file)
$ git commit -a
$ git checkout master
I've read A Guide to Branching in Mercurial. It said hg branch feature
. But what is next?
I don't follow.
Upvotes: 19
Views: 7836
Reputation: 73768
First note that git branch
is different from hg branch
. Branches created with hg branch
are permanent and live in a global name space, whereas branches made with git branch
are transient. The nearest equivalent of git branch
is hg bookmark
: bookmarks can be renamed and deleted and behave more like Git-branches.
I've recently written a guide for Mercurial bookmarks. Compare this with the named branch guide. Both guides contain worked examples of how to use (named) branches in Mercurial for keeping track of the development. It shows how to merge branches and how to close them or delete the bookmark when you are done.
Upvotes: 21
Reputation: 10173
If it's not a big feature (i.e. the branch doesn't have to have a name), it's quite simple.
Let's say your repository is at changeset X. You work on the feature as much as you like, commit, commit, commit and if you're happy with the result, continue as if you knew it would work all along. ;) If you aren't happy, do a hg update X
and continue development from there. All the work you did on your experiment will become an anonymous branch.
Strangely enough, it appears that Git doesn't provide such a way to work with anonymous branches which is what might be confusing you.
Upvotes: 8
Reputation: 27343
$ hg branch experimental (edit file) $ hg commit $ hg update default
Upvotes: 24