[英]Rebase feature branch onto another feature branch
I have two (private) feature branches that I'm working on. 我正在使用两个(专用)功能分支。
a -- b -- c <-- Master
\ \
\ d -- e <-- Branch1
\
f -- g <-- Branch2
After working on these branches a little while I've discovered that I need the changes from Branch2 in Branch1. 在这些分支上工作了一段时间之后,我发现我需要在Branch1中的Branch2中进行更改。 I'd like to rebase the changes in Branch2 onto Branch1. 我想将Branch2中的更改重新基于Branch1。 I'd like to end up with the following: 我想得出以下结论:
a -- b -- c <-- Master
\
d -- e -- f -- g <-- Branch1
I'm pretty sure I need to rebase the second branch onto the first, but I'm not entirely sure about the correct syntax and which branch I should have checked out. 我敢肯定,我需要第二分支衍合到第一,但我不完全确信正确的语法和分支我已签出。
Will this command produce the desired result? 这个命令会产生想要的结果吗?
(Branch1)$ git rebase --onto Branch1 Branch2
Switch to Branch2 切换到Branch2
git checkout Branch2
Apply the current (Branch2) changes on top of the Branch1 changes, staying in Branch2: 将当前(Branch2)更改应用到Branch1更改之上,并保持在Branch2中:
git rebase Branch1
Which would leave you with the desired result in Branch2: 这将使您在Branch2中获得理想的结果:
a -- b -- c <-- Master
\
d -- e <-- Branch1
\
d -- e -- f' -- g' <-- Branch2
You can delete Branch1. 您可以删除Branch1。
Note: if you were on Branch1
, you will with Git 2.0 (Q2 2014) be able to type: 注意:如果您使用的是Branch1
,则可以使用Git 2.0(2014年第二季度)输入:
git checkout Branch2
git rebase -
See commit 4f40740 by Brian Gesiak modocache
: 参见Brian Gesiak modocache
提交的commit modocache
:
rebase
: allow " -
" short-hand for the previous branch rebase
:允许“ -
”为上一个分支的缩写 Teach rebase the same shorthand as
checkout
andmerge
to name the branch torebase
the current branch on; 教重订同速记checkout
和merge
命名分支rebase
上当前分支; that is, that "-
" means "the branch we were previously on". 也就是说,“-
”表示“我们之前所在的分支”。
I know you asked to Rebase, but I'd Cherry-Pick the commits I wanted to move from Branch2 to Branch1 instead. 我知道您要求Rebase,但是我想让Cherry-Pick代替我想从Branch2移到Branch1的提交。 That way, I wouldn't need to care about when which branch was created from master, and I'd have more control over the merging. 这样,我就不必在乎何时从master创建哪个分支,并且我对合并有更多的控制权。
a -- b -- c <-- Master
\ \
\ d -- e -- f -- g <-- Branch1 (Cherry-Pick f & g)
\
f -- g <-- Branch2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.