2015-04-12 51 views
3

考慮下面的樹:如何「重新綁定」一次提交?

A --- B --- C --- D --- E --- F --- master 
\ 
    \ 
    B' --- C' --- D' --- topic 

其中(B != B')。我想做git rebase --onto master master topic但這會產生衝突。但情況更簡單:我想將單個topic提交到主。

git checkout master 
git cherry-pick topic 
git checkout topic 
git reset --hard master 
git checkout master 
git reset --hard HEAD~1 

是不是可以用一個命令執行上面的命令?

+0

爲什麼不直接修復衝突? –

+0

因爲實際上沒有衝突... – user3719454

+0

可能重複[git rebase單一提交](http://stackoverflow.com/questions/14635672/git-rebase-a-single-commit) –

回答

2

第一重置您的分支,然後使用引用日誌找到承諾櫻桃挑:

git checkout -B topic master # re-create topic branch at the commit of master 
git cherry-pick [email protected]{1} # copy the old tip of the topic branch 

另一個 - 甚至是簡單的 - 方式是通過衍合一系列的提交僅由您希望重新提交的單次提交:

git rebase --onto master topic^ topic 
+0

如果我明白' -B標誌正確,第二個櫻桃選擇應該說沒有什麼可做的,因爲它試圖挑選相同的提交主指向,我認爲'topic @ {1}'應該被直接散列承諾,糾正我,如果我錯了。 –

+0

@MohammadAbuShady:'topic @ {1}'引用分支指向的上一次提交。在結帳/重置之前,它指向'D',結帳後它指向'F'。 'topic @ {0}'爲'F','topic @ {1}'爲'D','topic @ {2}'爲'D'前指向的任何提交(最可能是'C '' – knittl

+0

hm,這很有趣,所以如果例如我做了'git rebase origin/develop',那麼我發現我搞砸了一個衝突或者什麼,我可以簡單地做一個'git reset --hard develop {1} '? –

相關問題