2012-10-31 25 views
5

我用我的本地副本與我們的共享存儲庫做了一系列愚蠢的步驟,我正在尋找一種方法要解決這個問題。步驟如下:如何在創建多頭分支,重新綁定和合並後創建新的頭像

  • 我用書籤有一個發展分支的多頭,其他人使用:

    -o---o---o-----o--- <- dev branch 
        \----1----1------ <- another head of the dev branch, 
             where I committed stuff 
    
  • 我創建了一個新的分支,還是局部的,一段時間後

    /---------------x <- new branch 
    -o---o---o-----o--- <- dev branch 
        \----1----1------ <- another head of the dev branch, 
             where I committed stuff 
    
  • 一個頭,只包含我的代碼,我做了重訂別的分支

        /-1'--1'-- <- rebase 
        /---------------x   <- new branch 
    -o---o---o-----o---   <- dev branch 
        \----1----1------   <- another head of the dev branch, 
                where I committed stuff 
    
  • 然後,我合併的底墊,然後,提交了幾次後,我合併默認

        ----------d-\  <-default 
               \ 
            /-1'--1'\  \ 
        /---------------x--------x--x-x-x-- <- new branch 
    -o---o---o-----o---   
        \----1----1------   
    

現在,我想我的新分支推送到服務器(hg push --new-branch -b newBranch) ,但我得到abort: push creates new remote head,因爲提交1'屬於dev分支。

什麼是正確的做法?我想避免創建這個額外的頭。

更新

每請求,這是hg heads輸出:

changeset: 839:f2033d695fcd <- want to push this 
branch:  newBranch 
tag:   tip 
user:  me 
date:  Wed Oct 31 13:05:51 2012 +0100 

changeset: 826:7fde19d7f467 
branch:  devBranch 
user:  my-collegue 
date:  Tue Oct 23 14:59:42 2012 +0200 

changeset: 820:23853bbf68df <- the part after rebase that got merged 
branch:  devBranch 
user:  me 
date:  Mon Oct 22 15:36:26 2012 +0200 

changeset: 807:899344cfb145 <- obsolete (branch with 1's) 
branch:  devBranch 
parent:  711:454f29c03fb1 
user:  me 
date:  Mon Oct 22 15:36:26 2012 +0200 

changeset: 712:d5e8a62a7f5f <- default, needs to stay 
parent:  648:2bbcc01aa191 
user:  me 
date:  Wed Aug 22 16:21:09 2012 +0200 
+0

不要使用自由的「繪圖」 - 你有控制檯命令和粘貼命令輸出的能力**格式**('hg log'或'hg glog' for tree here and at http://例如,stackoverflow.com/questions/11982648/reassigning-local-commits-to-a-different-branch-in-mercurial)。現在,請將'hg heads'的輸出與註釋相加 - 哪個頭已過時並且不能存在(完全或僅在推送目標中)。另外請閱讀關於push命令中的-r選項 –

+0

Hi @LazyBadger,我無法爲您提供'log'的輸出,因爲提交的提交比我描述的要多得多,而且我也忘記了爲了得到的確切命令這個狀態...更新問題以包含頭部的輸出。我不明白你對'-r'選項的引用,它是如何/爲什麼它應該有幫助? –

+0

在這種情況下不需要精確的命令 - **你**(不是我)必須看到devBranch的樹(從807和820的共同父項到826),定義* possible *(和* necessary *)合併devBranch的頭。或者只是'push -r f2033d695fcd'就足夠了 –

回答

1

我解決了這個問題,而無需按下另一頭回購,並沒有合併23853bbf68dfnewBranch。這可能不是最乾淨的方式,但我會將其作爲參考。簡而言之,我通過完成所有提交併重新應用它們來重建整個分支。

首先,我殺了newBranch「ES頭899344cfb145,通過使用帶的第一分支版本我做:

hg strip -r 646 

然後,我公司生產的電子郵件補丁(無法與MQ玩)所有提交這是newBranch,因爲它的成立:

hg export -g -r 797:808 -r 810 -r 815:822 -r 824:830 -o "%n-%m.patch" 
  • 797:808newBranch的補丁是在重訂基部分devBranch1'承諾從原來的數字)。
  • 810815:822newBranch中的其他補丁。 811:814屬於不同的分支,所以我不得不排除那些。
  • 823是與default合併提交,所以我跳過了這一個。
  • 824:830是與default合併後的所有提交。現在

,我對進口的newBranch一個新的頭這些補丁:

hg up -r 796 
# there are 29 patches, applying till merge 
hg import --bypass {01..21}*.patch 
hg up tip 
hg merge default 
hg ci -m 'merging in default' 
hg import --bypass {22..28}*.patch 

最後,我只是少了一份newBranch原頭。

hg strip -r 797 

這可能不適用於任何情況。在合併期間,我也必須解決一些衝突,但非常溫和。希望這可以幫助某人。

7

您可以只推一個磁頭你感興趣的善變。對於你,就意味着這樣做:

hg push -r f2033d695fcd 

如果目的地回購已經更新,你需要拉,合併,並重新推:

hg pull 
hg up -r <remote head> 
hg merge -r f2033d695fcd 
hg ci 
hg push 
+0

感謝您的答案,但正如我所提到的,這產生'中止:推分支devBranch'上創建新的遠程頭23853bbf68df。正如@LazyBadger所說,我會嘗試合併這個頭,儘管這是我想避免的。 –

+0

這是一個與你實際嘗試推動的不同的腦袋。如果你用'-r'指定頭部,你將不會得到這個頭部。 –

相關問題