如何将特性分支提交逐次迁移至develop分支并生成独立新提交
如何将特性分支的多个独立提交逐次迁移到develop分支?
需求
- 将特性分支(feature branch)上的若干提交逐次迁移至develop分支,生成全新的提交ID,与原特性分支提交无任何关联
- 必要时可逐提交手动解决合并冲突
已尝试操作
尝试用git format-patch生成补丁,再用git am应用,过程如下:
- 生成包含多个提交的补丁文件:
git format-patch [COMMIT ID] --stdout > ~/my.patch
- 切换到develop分支后执行:
git am --3way --ignore-whitespace ~/my.patch
遇到的错误
应用补丁时出现以下错误:
Applying: commit message 1 Applying: commit message 2 Applying: commit message 3 Applying: commit message 4 Applying: commit message 5 Using index info to reconstruct a base tree... M app/myfile1.py M app/myfile2.py M tests/test_myfile1.py error: patch failed: app/myfile1.py:61 error: app/myfile1.py: patch does not apply error: patch failed: app/myfile3.py:58 error: app/myfile3.py: patch does not apply error: Did you hand edit your patch? It does not apply to blobs recorded in its index. Patch failed at 0005 Review hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
注:未手动修改过生成的补丁文件。
尝试用git mergetool手动解决冲突时,系统提示:
No files need merging
补充说明
以下方法可以处理合并冲突,但会将所有提交合并为单个提交,不符合逐次迁移的需求:
git checkout feature git diff [COMMIT ID] > ~/my.patch git checkout develop git apply --3way ~/my.patch
内容的提问来源于stack exchange,提问作者DarkTrick
相关产品推荐
相关产品推荐

