Git 如何将分支重设为间接父分支?

Git 如何将分支重设为间接父分支?,git,rebase,Git,Rebase,我从master分支到feature1,从feature1分支到feature2。但实际上,我想将这两个特性从master中分离出来。我尝试了git rebase master,但这只会产生当前分支功能2是最新的。 为什么它不能像我期望的那样工作? 我如何将feature2重新设置为master的分支 git init echo "masterstuff" >> file.txt git add file.txt && git commit -m

我从
master
分支到
feature1
,从
feature1
分支到
feature2
。但实际上,我想将这两个特性从
master
中分离出来。我尝试了
git rebase master
,但这只会产生
当前分支功能2是最新的。

为什么它不能像我期望的那样工作?
我如何将feature2重新设置为master的分支

git init
echo "masterstuff" >> file.txt
git add file.txt && git commit -m "initial commit"
git checkout -b feature1
echo "branch1 specific" >> file.txt 
git add file.txt && git commit -m "start of feature1"
git checkout -b feature2
echo "feature2 specific" >> file.txt
git add file.txt && git commit -m "start of feature2"
现在我有

* [master] -- * [feature1] -- * [feature2] 
想要

* [master] -- * [feature1]
           \- * [feature2]
准确地假设您给出的“叙述”:

git init
echo "masterstuff" >> file.txt
git add file.txt && git commit -m "initial commit"
git checkout -b feature1
echo "branch1 specific" >> file.txt 
git add file.txt && git commit -m "start of feature1"
git checkout -b feature2
echo "feature2 specific" >> file.txt
git add file.txt && git commit -m "start of feature2"
在您停止“叙述”的时候,您仍然在使用
功能2
,接下来您会说:

git rebase --onto master feature1
然后(对于这个特殊的“叙述”),你将有一个冲突需要解决!解决它(可能通过手动编辑file.txt),然后

git add file.txt
git rebase --continue
结果:

* 72395ff (HEAD -> feature2) start of feature2
| * b59e979 (feature1) start of feature1
|/  
* 2ab1296 (master) initial commit

…关于上述观点,请包括实际的分支图(或至少是它们的表示)。嗯@TimBiegeleisen OP确实给出了达成回购状态的完整步骤说明。我可以解释为什么存在冲突,但这将使我们超出特定问题的范围。请注意,
--on
语法是真正的
rebase
语法;正如你建议的那样,省略它是一条捷径,而且在很多情况下(像你一样),这种捷径是不合适的。换句话说,您可以而且可能应该始终使用
--on
;一开始有点让人困惑,但你会很快习惯的。这是一个很有趣的想法,可以经常使用。我认为这确实有助于清晰地理解--on语法。但您是否发现自己实际上在origin/master origin/master上键入了
git-rebase--D