2016-12-15 168 views
1

我參與了一個相當大的項目,其中有很多開發人員。對於某個功能開發,創建了一個新分支(我們稱之爲分支feature_a)。選擇性合併/衝突解決

現在在嘗試合併masterfeature_a時,在各個「模塊」中存在多個衝突,其中不同的開發人員負責這些模塊。

我該如何獨立解決我負責的文件中的衝突,並讓其他文件不合並?

+0

你不能離開其他文件未合併,則必須提交一些這些文件。在Git中,提交涉及資源庫中的_every_文件。您可能希望得到的最好的結果是與其他開發人員合作併合並在一起。 –

回答

1

你可以重寫的feature_a的歷史,它在提交每個承諾是一個單developper的責任列表拆分,然後讓每個developper合併「自己的」代碼回到master

下面是這種想法的大綱:

# from branch feature_a : 

# create a new branch : 
$ git checkout -b merge_feature_a 

# find commit where it forked from `master` : 
$ git merge-base master feature_1 
0125638 

# reset current merge_feature_a to this commit : 
$ git reset 0125638 

# diff feature_a and merge-base to get the full list of modified files : 
$ git diff --name-only 0125638 feature_a 

# create first commit with files which are Mike's responsibility : 
$ git add <files for Mike> 
$ git commit -m "feature_a for Mike" 

# same for Sally : 
$ git add <files for Sally> 
$ git commit -m "feature_a for Sally" 

# etc ... 

# push this new branch : 
$ git push origin merge_feature_a 

# tell Mike to merge first commit, 
# when he's done tell Sally to merge second commit, 
# etc ... 

你得到的這種方式是合併的序列提交,在最終的結果是(希望)你希望的內容。


加分點:創建一個合併在歷史

合適的地方提交一旦合併過程完成後,你可以用歷史不甘示弱,從而顯示該內容作爲提交加盟無論是一部開拓創新master分支與原feature_a分支:

# from master : 

# rewind master to its state before any merge : 
# use '--soft' to keep every modifications in the index 
# (your next commit will have this content) 
$ git reset --soft 1e67a9bb # <- insert the hash of the original master 

# get the sha1 of the commit for feature_a : 
$ git rev-parse feature_a 
e9573881e2eff04d219e57dfd4d7739aa5c11693 

# write this hash into '.git/MERGE_HEAD' : 
$ git rev-parse feature_a > .git/MERGE_HEAD 

# commit : the presence of the MERGE_HEAD file indicates a merge commit 
$ git commit 
+1

是的,我一直在想,但是希望避免創建一個新的分支。儘管解決了這個問題。感謝您花時間詳細解釋這一點。 – schaazzz