2012-11-29 62 views
3

我的難題是這樣的。我的團隊成員修改了供應商組件。這個組件然後升級到當前版本,覆蓋我的團隊的變化。Git'合併',但指定遠程/本地/基地提交在同一分支

有問題的部分有我的隊友做出的重大更改,但升級時添加了最小的更改。我所擁有的是這樣的:

---component version 1.0----team change A---team change B---component version 2.0 
     (stock)            (result of upgrade) 

我想是做合併,像這樣:

  ----team change A---team change B 
     /        \ 
---component version 1.0     successful 'merge' 
     (stock)       /
     \------------component version 2.0 
         (result of upgrade) 

的基本原理是將球隊的變化是比較容易,如果我們可以看到從component version 1.0供應商的變化到component version 2.0,我們從component version 1.0更改爲team change B併合並這兩組更改。

據我瞭解,要做到這一點的唯一方法是將分支重置爲team change B,從component version 1.0檢出一個新的分支和component version 1.0component version 2.0之間適用的差異作爲一個修補程序,合併分支機構創建的,並提交解析度。

我希望有一種方法可以基本上模擬像git merge --BASE='component version 1.0' --LOCAL='team change B' --REMOTE='component version 2.0'這樣的合併,這樣我就可以使用合併解析工具來確定生成的文件的外觀。

回答

1

如果您不想要重置分支(也許這已經發布到共享存儲庫,並且你不希望人們必須處理強制更新s),您可以簡單地將升級恢復到版本2.0,在版本1.0導入的分支上重新升級到版本2.0,然後合併該分支。

例如(假設你的分支稱爲mastermaster當前已檢出):

# create a commit that is the opposite of HEAD, effectively undoing it 
git revert HEAD^ 
# create a new branch based on the original vendor import 
git checkout -b vendor <sha1-of-vendor-1.0-commit> 
# import the vendor 2.0 code 
git read-tree -u --reset master^ 
git commit -m "vendor 2.0 code" 
# merge in the new vendor code 
git checkout master 
git merge vendor 
+0

復位的主人是不是一種選擇。我實際上最終使用了araxis merge的三路diff/merge功能。在每個窗口中選擇相同的文件,然後在每個窗格中選擇不同的版本:左側團隊更改B,中間通用祖先,右側組件版本2.0。如果我沒有進入實踐,這將是最好的答案。 – kayaker243

0

你應該能夠做到這一點這樣(假設master是你的分支的名稱,它可能不是):根據球隊的變化性質

git checkout master 
git reset --hard <SHA of team change B> 
git checkout -b vendor-upgrade <SHA of component version 1.0> 
# replace contents of working directory with component version 2.0 
git add <everything that needs to be added> 
git commit -m "component version 2.0" 
git checkout master 
git merge vendor-upgrade 

,你可能有一些合併衝突來處理,並且取決於您是否在完成之後刪除vendor-upgrade分支,或者只是將其留在那裏以便在不可避免的版本3.0出來時進行分配......

相關問題