git修补分支子范围的最佳方法是什么?

jsc*_*oot 21 git

在Subversion中,使用"svn merge -ra:b mybranch"很容易从分支合并一系列变更集/差异.但是在git中,我发现只能从分支机构中选择一个提交来将该补丁应用到我当前的工作分支.所以我想知道是否有一种快速的方法可以在一个错误修复分支中的两个标签之间一举应用所有提交到我当前的主分支?

CB *_*ley 49

执行您正在寻找的操作的最简单方法是使用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
Run Code Online (Sandbox Code Playgroud)

  • 哦,只是为了澄清'因为我没有得到它,标签A实际上是在你要包含的系列中的第一个之前的提交 - 正确 - 之前.因此标签A不会被包含在内,只会包含标签. (5认同)

小智 5

我发现这样做最简单的方法是:

git cherry-pick starthash..endhash
Run Code Online (Sandbox Code Playgroud)

请注意,这两个点没有空格将它们与哈希标签分开.

  • 请注意,这不是樱桃挑选starthash,而是在starthash之后的所有内容,包括endhash.要包含starthash,请执行"git cherry-pick starthash ^ .. endhash" (3认同)