2016-02-12 23 views
0

在一個項目中,我有一個dev分支,該分支最新爲master將分支應用於過去的提交

我想將dev分支更改到分支past-master,這基本上是在先前的提交時停止的master版本。

我試過git rebase devpast-master但是在應用分支之前重播past-mastermaster之間的所有提交。
git cherry-pick A^..B其中A是第一個dev提交,B是最後一個在past-master,由於某種原因失敗。

要在dev分支和運行git format-patch past-master產生的所有提交斑塊,並從dev分支逐一past-master工程應用的,但感覺非常不理想。

有沒有一個很好的方法來做到這一點?

回答

0

閱讀關於rebase的manpage應該清楚了這一切。遊戲中有三個提交:HEAD,上游和上。

它提交的提交是上游..HEAD。它將它們應用到分支上。如果沒有 - onto,就會設置爲上游。但你希望:

HEAD:開發

上游:主

到:過去的主

git rebase --onto past-master master dev 

的手冊頁中有這個確切的例子。唯一的區別是past-master的所有提交都可以從master獲得,而在本例中,next有一些不可達的提交。但這不是障礙:

Here is how you would transplant a topic branch based on one branch to another, to pretend that you forked the topic branch from the latter branch, using rebase --onto. 

    First let’s assume your topic is based on branch next. For example, a feature developed in topic depends on some functionality which is found in next. 

      o---o---o---o---o master 
       \ 
       o---o---o---o---o next 
            \ 
            o---o---o topic 

    We want to make topic forked from branch master; for example, because the functionality on which topic depends was merged into the more stable master branch. We want our tree to look like this: 

      o---o---o---o---o master 
       |   \ 
       |    o'--o'--o' topic 
       \ 
       o---o---o---o---o next 

    We can get this using the following command: 

     git rebase --onto master next topic 
+0

謝謝,按預期工作! – Eric