2011-08-20 39 views
3

顯然,我已經檢查的最後幾個星期的提交到一個分支。除了對一個文件的更改外,我想將所有內容都提交給主幹。我該怎麼辦?水銀/ HG:得到改變出的分支,進入主幹

+3

將合併分支到主幹是一個可接受的解決方案? –

+0

@Matt - 是的,我認爲會的。我只是這樣做了,但是當我必須手動合併我的配置文件時,我會付錢。 – Marcin

回答

5

當你談論命名分支與水銀你在談論一個變更的永久屬性。變更集不能位於不同的分支上,仍然是相同的變更集。你可以(如@馬特球)認爲分支的結果合併到默認:

hg update default 
hg merge thebranchname 

或者你也可以的,瘋狂的,歷史的破壞扭曲經過假裝這些變化的一個分支沒有完成(如@Rudi詳情(抱歉))。

只是現在就合併,並考慮在將來考慮使用書籤,匿名分支或單獨的克隆,因爲您無法立即推送 - 無法在變更集上創建永久註釋。

1

如果您沒有推出新分支的任何變更集,並且在分支中沒有合併,則可以使用mq擴展名將中繼線不需要的變更集移動到分支尖端。

$EDITOR ~/.hgrc 
[extensions] 
mq = 
«save+quit» 
# import all revisions up to the unwanted rev into a patch queue 
hg qimport -r$BRANCH_TIP_REVISION:$IN_TRUNK_UNWANTED_REVISION 

# edit the order of the patches, so that the unwanted patch is the last patch 
$EDITOR .hg/patches/series 
    «Move the in trunk unwanted patch to the last line of the file» 
# Variant 1: don't change the branch 
hg qpush -a # apply all patches 
hg qfinish -a # finish all patches to regular hg changesets 
hg log -l2  # find out the revision number of the latest revision you want in trunk 
hg up -r trunk # checkout trunk 
hg merge -r $LATEST_WANTED_REVISION_NUMBER # merge only the wanted changesets 

# Variant 2: *All* patches are on the new branch, and 
# you want only the differing changeset on the new branch 
hg up -r trunk # move the working copy to trunk 
hg qpush -a # apply all patches 
hg qpop  # unapply the unwanted one 
hg qfinish  # finish the applied patches 
hg branch $OLD_BRANCH_NAME # switch the working copy to the new branch 
          # if there is already another branch of this name, 
          # you need to checkout the other branch, apply the 
          # patch and merge trunk into that branch afterwards. 
hg qpush  # apply the branch-specific patch 
hg qfinish -a # finish the patch 
+0

這很有趣,包括MQ解決方案如何總是複雜的,多步驟的過程中結束了:) –

+1

由於汞遵循這樣的原則「不改寫歷史,如果它是不是真的有必要」,HG故意不讓它特別容易做。重寫歷史記錄以重新排序涉及分支的任意變更集是相當大的手術。使用MQ實際上使得這個過程更容易出錯。 –