2009-09-21 14 views

回答

20

hg branch X確實沒有除了告訴Mercurial「我做的下一個提交應該在分支X上。」它並不實際「創建」分支。分支機構不存在,直到有至少一個提交就可以了:

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 
$ 

所以回答你的問題是:「用hg branch branch-A來紀念下承諾爲分支-A」

+3

偉大的信息,但可能值得添加的方式來做OP是試圖做的事情:hg branch branchA;提交給branchA; hg更新默認; hg分支branchB,提交給branchB。關鍵是「hg update default」,所以branchB基於與branchA相同的提交。 – 2009-09-21 15:38:48

+0

良好的信息,糟糕的解釋。 sjl在ecgtheow ..呃..?也是hg com,爲Google員工做這個hg commit。人們不應該需要解讀答案。對不起,但-1。 – Stolas 2014-02-13 08:14:07

+0

您好史蒂夫,您爲什麼不以比現在更明確的方式在您的指南中添加此信息?可以改進指南。 (「hg branch X除了告訴Mercurial外什麼都不做,」下一個我提交的提交應該在分支X上「。它實際上並沒有」創建「這個分支,直到至少有一個提交爲止,分支纔會存在。 – 2014-05-04 16:51:49

-5

使用'hg update -C branch-name'。

+0

否。如果分支命令一個接一個地發生,第一個分支將不存在,因爲它上沒有提交。此外,盲目使用-C與更新不是一個好主意。使用-c通常更安全,只有在你真正需要時才使用-C。 – 2009-09-21 12:02:29

0

卡爾·邁耶說我會去:

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

諷刺的是,我認爲史蒂夫Losh提供他的指導一個更好的答案,然後在這裏(雖然「A分支不存在,直到有至少一個承諾「是我在指南中添加的一個非常好的提示)。

如果您閱讀section on named branches,他會簡要說明它們如何工作以及如何在它們之間切換。