我参与了一个相当大的项目,其中有很多开发人员。对于某个功能开发,创建了一个新分支(我们称之为分支feature_a
)。选择性合并/冲突解决
现在在尝试合并master
到feature_a
时,在各个“模块”中存在多个冲突,其中不同的开发人员负责这些模块。
我该如何独立解决我负责的文件中的冲突,并让其他文件不合并?
我参与了一个相当大的项目,其中有很多开发人员。对于某个功能开发,创建了一个新分支(我们称之为分支feature_a
)。选择性合并/冲突解决
现在在尝试合并master
到feature_a
时,在各个“模块”中存在多个冲突,其中不同的开发人员负责这些模块。
我该如何独立解决我负责的文件中的冲突,并让其他文件不合并?
你可以重写的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
是的,我一直在想,但是希望避免创建一个新的分支。尽管解决了这个问题。感谢您花时间详细解释这一点。 – schaazzz
你不能离开其他文件未合并,则必须提交一些这些文件。在Git中,提交涉及资源库中的_every_文件。您可能希望得到的最好的结果是与其他开发人员合作并合并在一起。 –