git 将功能分支变基到另一个功能分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14893399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rebase feature branch onto another feature branch
提问by Arjen
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. I'd like to rebase the changes in Branch2 onto Branch1. I'd like to end up with the following:
在这些分支上工作一段时间后,我发现我需要在 Branch1 中对 Branch2 进行更改。我想将 Branch2 中的更改重新定位到 Branch1。我想结束以下内容:
a -- b -- c <-- Master
\
d -- e -- f -- g <-- Branch1
I'm pretty sure I need to rebase the second branch ontothe 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
回答by sasikt
Switch to Branch2
git checkout Branch2
Apply the current (Branch2) changes on top of the Branch1 changes, staying in Branch2:
git rebase Branch1
切换到分支 2
git checkout Branch2
在 Branch1 更改之上应用当前 (Branch2) 更改,停留在 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。
回答by VonC
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 4f40740by Brian Gesiak modocache
:
见提交4f40740由布莱恩Gesiakmodocache
:
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; that is, that "-
" means "the branch we were previously on".
教 rebase 相同的速记
checkout
并将merge
分支命名rebase
为当前分支;也就是说,“-
”的意思是“我们之前所在的分支”。
回答by Craigo
I know you asked to Rebase, but I'd Cherry-Pick the commits I wanted to move from Branch2 to Branch1 instead. 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.
我知道你要求 Rebase,但我会选择我想从 Branch2 移动到 Branch1 的提交。这样,我就不需要关心什么时候从 master 创建了哪个分支,而且我可以更好地控制合并。
a -- b -- c <-- Master
\ \
\ d -- e -- f -- g <-- Branch1 (Cherry-Pick f & g)
\
f -- g <-- Branch2