选择性 Merge/Conflict 分辨率
Selective Merge/Conflict Resolution
我参与了一个相当大的项目,其中有很多开发人员。为了某个功能开发,创建了一个新分支(我们称这个分支为feature_a
)。
现在,在尝试将 master
合并到 feature_a
时,各种 "modules" 中存在多个冲突,不同的开发人员负责这些模块。
我如何独立解决我负责的文件中的冲突,而不合并其他文件?
您可以重写 feature_a
的历史记录,将其拆分为提交列表,其中每个提交由一个开发人员负责,然后让每个开发人员将其 "own" 代码合并回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 ...
您通过这种方式得到的是一系列合并提交,最终结果(希望)是您想要的内容。
奖励积分:在历史记录的正确位置创建合并提交
合并过程完成后,您可以 fiddle 历史记录,以便此内容显示为加入原始 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
我参与了一个相当大的项目,其中有很多开发人员。为了某个功能开发,创建了一个新分支(我们称这个分支为feature_a
)。
现在,在尝试将 master
合并到 feature_a
时,各种 "modules" 中存在多个冲突,不同的开发人员负责这些模块。
我如何独立解决我负责的文件中的冲突,而不合并其他文件?
您可以重写 feature_a
的历史记录,将其拆分为提交列表,其中每个提交由一个开发人员负责,然后让每个开发人员将其 "own" 代码合并回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 ...
您通过这种方式得到的是一系列合并提交,最终结果(希望)是您想要的内容。
奖励积分:在历史记录的正确位置创建合并提交
合并过程完成后,您可以 fiddle 历史记录,以便此内容显示为加入原始 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