如何使用 cherry-pick 或任何其他方法将提交(包含 2-3 个文件)从一个分支移动到另一个分支

How to Move commit(contains 2-3 files) from one branch to another branch using cherry-pick or any other method

我有两个分支,一个是 master 分支,另一个是 development 分支。

我一直在尝试使用 cherry-pick 方法将提交从 development 移动到 master。如果提交已在任何一个文件中进行了编辑或更新,则此方法对我来说效果很好。但在我的场景中,两到三个文件在一次提交中被编辑和推送。我需要将这些提交移至我的 master 分支。

所以当我尝试cherry-pick时,我无法将其移出。我只能移动在单次提交中编辑的单个文件,无法移动在单次提交中编辑的多个文件。我正在寻找问题的解决方案。

您可以使用 git cherry-pick,您只需要解决您的合并冲突。参见 How to resolve merge conflicts in Git

假设 commit-a, commit-b commit-c 是你在开发分支上的三个提交,你想移动到 master 要移动第一个提交,运行:

git cherry-pick <sha-id-of-commit-a>

解决冲突,加入索引,运行

git cherry-pick --continue

然后移动第二个提交

git cherry-pick <sha-id-of-commit-b>

解决冲突,添加到索引和运行

git cherry-pick --continue

然后移动第三个提交

git cherry-pick <sha-id-of-commit-c> 

解决冲突,添加到索引和运行

git cherry-pick --continue