3 回答
TA贡献2041条经验 获得超4个赞
一个可能的和经过测试的解决方案,用于将分支B合并到我们的签出分支A中:
# in case branchA is not our current branch
git checkout branchA
# make merge commit but without conflicts!!
# the contents of 'ours' will be discarded later
git merge -s ours branchB
# make temporary branch to merged commit
git branch branchTEMP
# get contents of working tree and index to the one of branchB
git reset --hard branchB
# reset to our merged commit but
# keep contents of working tree and index
git reset --soft branchTEMP
# change the contents of the merged commit
# with the contents of branchB
git commit --amend
# get rid off our temporary branch
git branch -D branchTEMP
# verify that the merge commit contains only contents of branchB
git diff HEAD branchB
要使其自动化,可以使用分支A和分支B作为参数将其包装到脚本中。
此解决方案保留合并提交的第一个和第二个父级,正如您所期望的git merge -s theirs branchB.
- 3 回答
- 0 关注
- 542 浏览
添加回答
举报