views:

151

answers:

2

Let's say I create two banches at the same time:

hg branch branch-A
hg branch branch-B

How do I send my next commit to branch-A instead of branch-B?

A: 

Use 'hg update -C branch-name'.

NawaMan
No. If the branch commands happen one after another the first branch won't exist because there are no commits on it. Also, blindly using -C with update is not a good idea. It's much safer to use -c normally and only use -C when you really need it.
Steve Losh
+3  A: 

hg branch X does nothing except tell Mercurial "the next commit I make should be on branch X." It doesn't actually "create" the branch. A branch doesn't exist until there's at least one commit on it:

sjl at ecgtheow in ~/Desktop/test on default at tip
$ hg branch a
marked working directory as branch a

sjl at ecgtheow in ~/Desktop/test on a at tip
$ hg branch b
marked working directory as branch b

sjl at ecgtheow in ~/Desktop/test on b at tip
$ hg branches
default                        0:aae011bc1b00

sjl at ecgtheow in ~/Desktop/test on b at tip
$ echo foo >> x

sjl at ecgtheow in ~/Desktop/test on b at tip!
$ hg com -m1

sjl at ecgtheow in ~/Desktop/test on b at tip
$ hg branches
b                              1:b66106035d8d
default                        0:aae011bc1b00 (inactive)

sjl at ecgtheow in ~/Desktop/test on b at tip
$

So the answer to your question is: "use hg branch branch-A to mark the next commit as being on branch-A."

Steve Losh
Great info, but might be worth adding the way to do what OP is trying to do: hg branch branchA; commit to branchA; hg update default; hg branch branchB, commit to branchB. The key is "hg update default", so branchB is based on the same commit as branchA.
Carl Meyer