在Subversion中,使用“svn merge -r a:b mybranch”可以轻松地合并一个分支中的一系列变更集/差异。但是在Git中,我发现只能从分支中精选单个提交并将该补丁应用到我的当前工作分支。所以我想知道是否有一种快速的方法可以一次性将错误修复分支中两个标签之间的所有提交应用到我的当前主分支。
执行您要查找的操作最简单的方法是使用 git rebase
。以下是一个步骤。假设标签A是您想要选择的补丁系列所基于的提交,并且标签B是系列中最终补丁的提交。此外,假设br是当前分支的名称以及应该应用新补丁系列的分支。
# Checkout a new temporary branch at the current location
git checkout -b tmp
# Move the br branch to the head of the new patchset
git branch -f br B
# Rebase the patchset onto tmp, the old location of br
git rebase --onto tmp A br
git cherry-pick starthash..endhash