uzo
uzo

Reputation: 2821

Defining which branch my next commit is added to

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?

Upvotes: 12

Views: 7467

Answers (3)

Niccolò
Niccolò

Reputation: 3102

As Carl Meyer says I'd go for:

hg branch branch-A
commit branch-A
hg update default
hg branch branch-B
commit branch-B

Ironically, I think Steve Losh provides a better answer on his guide then here (though "A branch doesn't exist until there's at least one commit on it" is a very good tip that I'd add in the guide).

If you read the section on named branches, he gives a concise explanation on how they work and how to switch between them.

Upvotes: 0

Steve Losh
Steve Losh

Reputation: 19892

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."

Upvotes: 22

NawaMan
NawaMan

Reputation: 25677

Use 'hg update -C branch-name'.

Upvotes: -5

Related Questions