如何将分支变基到间接父分支?

How to rebase a branch onto an indirect parent branch?

我从 master 分支到 feature1,从 feature1 分支到 feature2。但我实际上想将这两个功能从 master 中分离出来。我试过 git rebase master 但这只会产生 Current branch feature2 is up to date.
为什么它不像我预期的那样工作?
我如何将 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"

在你停止“叙述”的地方,你还在feature2,你接下来会说:

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