Git cherry-pick 范围
Git cherry-pick range
我如何cherry-pick提交C4
和C5
?
我试过 git cherry-pick C4..C5
但我只得到 C4
。
我想我真的不明白这个范围是如何工作的。
TL;DR 版本:C4^..C5
除非命令对其进行特殊处理(而 git cherry-pick
不会),否则范围表达式表示 "take all commits identified/findable by the right-side name, minus all commits identified/findable by the left-side name"。在这种情况下,C5
标识提交 0 到 5(含),C4
标识 0 到 4(含)。从第一组中减去第二组提交只剩下 C5
.
另一种看待它的方式是,如果提交是相关的,你会得到一个 "half open interval",就像 (3, 7]
中的整数是 4 5 6 7
一样。
与半开整数区间一样,通常的简单技巧是从后退一步开始。由于 C4
的(第一个)父级是 C4^
,因此 C4^..C5
可以解决问题,就像 (2, 7]
会得到 3 4 5 6 7
.
(如果没有父项,则失败,即左侧是根提交。在这种情况下,您需要一些替代策略。有些命令使这更容易,有些更难,但现在我们可以忽略问题。:-))
在这种特定情况下,您不需要使用范围。
示例来自 man git-cherry-pick
:
git cherry-pick master~4 master~2
Apply the changes introduced by the fifth and third last commits pointed to by master and create 2 new commits with these changes.
所以对你来说:
git cherry-pick C4 C5
我如何cherry-pick提交C4
和C5
?
我试过 git cherry-pick C4..C5
但我只得到 C4
。
我想我真的不明白这个范围是如何工作的。
TL;DR 版本:C4^..C5
除非命令对其进行特殊处理(而 git cherry-pick
不会),否则范围表达式表示 "take all commits identified/findable by the right-side name, minus all commits identified/findable by the left-side name"。在这种情况下,C5
标识提交 0 到 5(含),C4
标识 0 到 4(含)。从第一组中减去第二组提交只剩下 C5
.
另一种看待它的方式是,如果提交是相关的,你会得到一个 "half open interval",就像 (3, 7]
中的整数是 4 5 6 7
一样。
与半开整数区间一样,通常的简单技巧是从后退一步开始。由于 C4
的(第一个)父级是 C4^
,因此 C4^..C5
可以解决问题,就像 (2, 7]
会得到 3 4 5 6 7
.
(如果没有父项,则失败,即左侧是根提交。在这种情况下,您需要一些替代策略。有些命令使这更容易,有些更难,但现在我们可以忽略问题。:-))
在这种特定情况下,您不需要使用范围。
示例来自 man git-cherry-pick
:
git cherry-pick master~4 master~2
Apply the changes introduced by the fifth and third last commits pointed to by master and create 2 new commits with these changes.
所以对你来说:
git cherry-pick C4 C5