2013-02-06 65 views
3

我遇到了一種情況,在此之前某個分支合併到主分支中,並且分支中的更改不再位於主分支中。可能這是由於合併衝突處理不當,但在這個時候我並不確定。Git在之前合併的分支中合併

在此之前合併分支的變化都需要在主分支,但現在如果我嘗試合併到主Git的返回消息分支「已經跟上時代的。」因爲此分支先前已合併。強制將此分支重新合併爲主的最佳方式是什麼?

回答

2

我認爲這會做雅

mkdir alreadyapplied.patches 
git format-patch -o alreadyapplied.patches master..alreadyapplied 

然後

git checkout -b wip master 
git am alreadapplied.patches 
# (do whatever's necessary to deal with conflicts here) 
# (rebase wip here if the conflict resolution has taken 
# long enough that the wip branch has gotten behind master) 
git checkout -B master wip 
git branch -d wip  
0

根據多少提交參​​與你可以只cherry-pick各一轉。

+1

因爲這個部門已經有提交的顯著數量。理想情況下,我正在尋找一種方法,可以將整個分支重新合併到一起,並在提交更改之前執行手動衝突解決。 – bigtunacan

0

另一種方法是讓在合併之前提交分支機構的ID和重置你的頭指向它,那麼你可以做你需要做那支重新合併到主任何修復

git reset (--hard/--soft/--mixed) _commit_ # where the _commit_ is the commit ID of the old branch 
<work and make changes> 
git commit -m "Made changes to commit before merging into master" 
git checkout master 
git merge (--no-ff) otherBranch 

重置您的HEAD將有效地讓您回到事情是如何承諾的。請注意,使用--hard選項可能會非常危險,因爲它具有破壞性,並且會使您的索引和工作區看起來與提交階段完全相同(您將失去其他工作)。