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 關注
- 580 瀏覽
添加回答
舉報
