You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将特性分支提交逐次迁移至develop分支并生成独立新提交

如何将特性分支的多个独立提交逐次迁移到develop分支?

需求

  • 将特性分支(feature branch)上的若干提交逐次迁移至develop分支,生成全新的提交ID,与原特性分支提交无任何关联
  • 必要时可逐提交手动解决合并冲突

已尝试操作

尝试用git format-patch生成补丁,再用git am应用,过程如下:

  1. 生成包含多个提交的补丁文件:
git format-patch [COMMIT ID] --stdout > ~/my.patch
  1. 切换到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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 10:05:31