我假设C
是合并提交,这就是您不想将其包含在结果中的原因。
为了做你想做的事,你需要的是git 变基 http://git-scm.com/docs/git-rebase
让我们从另一个示意性提交图开始。想要留下原来的
分支完好无损,我们将在一个名为的新分支上运行rebasing
git checkout -b rebasing master
--> A --> B------------------- --> C --> D (branch master) (branch rebasing)
\ /
+----+-> F --> G --> H -+ (branch topic)
只需重新设置之间的所有内容topic
and rebasing
onto topic
.
git rebase --onto topic topic rebasing
或者使用更短的命令执行相同的操作
git rebase topic
-> A -> B -----------------> C -> D (branch master)
\ /
+---+> F -> G -> H + (branch topic)
\
+---------> B -> D (branch rebasing)
现在当我们看看rebasing
我们有一个直线形式A
to D
.
-> A -> F -> G -> H -> B -> D (branch rebasing)
所以,现在唯一的问题可能是顺序与原来的不同
你期望的。您可以通过重新排序提交来轻松解决这个问题git rebase
--interactive
, 如果你想。
或者您以稍微复杂的方式重新设置所有内容。我们重来。
--> A --> B------------------- --> C --> D (branch master) (branch rebasing)
\ /
+----+-> F --> G --> H -+ (branch topic)
首先从C
到尖端master
(aka. D
)并将其放在
的尖端topic
(aka. H
) :
git rebase --onto topic C master
-> A -> B ----------------> C -> D (branch master)
\ /
+----> F -> G -> H + (branch topic)
\
+---------> D (branch rebasing)
最后一次rebase,我们就完成了。
git rebase B
+----> F -> G -> H + (branch topic)
/ \
-> A -> B ----------------> C -> D (branch master)
\
+------------------------> F -> G -> H -> D (branch rebasing)
Voila!
-> A -> B -> F -> G -> H -> D (branch rebasing)