tags:

views:

437

answers:

3

Hi,

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 read http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/, it said ' hg branch feature'. But what is next? I don't follow.

I appreciate if you can help.

Thank you.

+1  A: 
$ hg branch experimental

(edit file)
$ hg commit
$ hg update default
sblom
Do I need to hg commit all the changes I made in 'default' before I do 'hg branch experimental'?
michael
Yeah--you do, assuming you want the pending changes to go in the default branch. Otherwise, the pending changes follow you over to the branch that you've named "experimental", and you can commit them there.
sblom
+1  A: 

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.

Tomislav Nakic-Alfirevic
+1  A: 

I suggest reading my guide here:

http://mercurial.aragost.com/kick-start/tasks.html

It has a worked example of how to use named branches in Mercurial for keeping track of the development. It shows how ot merge branches and how to close them when you are done.

Martin Geisler
Useful walk through for named branches, though it is also useful to be aware of anonymous branches (as Tomislav points out).
dfaivre
dfaivre: yeah, I agree with Tomislav.
Martin Geisler