我参与了一个有很多开发人员的大型项目。对于某个功能开发,创建了一个新分支(让我们称之为分支feature_a
)。
现在,在尝试将master
合并到feature_a
时,各种“模块”中存在多个冲突,其中不同的开发人员负责这些模块。
如何独立解决我负责的文件中的冲突并将其他文件保持未合并状态?
答案 0 :(得分:1)
您可以重写feature_a
的历史记录,将其拆分为一个提交列表,其中每个提交是一个开发人员的责任,然后让每个开发人员合并其自己的"代码回到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 ...
你通过这种方式获得的是一系列合并提交,最终结果是(希望)你想要的内容。
奖励积分:在历史记录的正确位置创建合并提交
合并过程完成后,您可以摆弄历史记录,以便将此内容显示为加入orignal 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