首页 > 解决方案 > 尝试压缩提交后,交互式变基不断添加步骤

问题描述

当我的分支基于自身以通过将它们压缩在一起来清理提交时,我的 rebase 卡在一个循环中,不知道如何打破这个。这适用于我正在处理的每个分支,而不仅仅是一个特定的分支。

例如说我有一个分支my-branch三个提交

commit 1
commit 2
commit 3

在我的终端中,我写git rebase -i origin my-branch

这将我带到了交互式 git(以我的 Sublime 文本为例)

在这里,我看到了我所有的提交并将最后一个更改为 squash,这样我就只有提交 1 和 2:

p commit 1
p commit 2
s commit 3

从这里,我看到另一个交互式窗口,在其中我删除了提交 3 的提交消息,只留下了提交 2。

这一切似乎都在工作,但现在陷入了一个循环。

例如,在我的终端上,它位于变基 STEP 3/3 上,然后我rebase --continue继续执行 STEP 4/4(没有更改)rebase --continue,再次执行 STEP 5/5,依此类推,而实际上并未离开变基。

我被迫使用rebase --abort并且我的提交不是壁球。

标签: git

解决方案


如果你想压缩到最后 rebase,你可以跳过使用 rebase -i 这个技巧:

git checkout my-feature
git merge master # merge with the branch you want to rebase onto
# don't worry, that will go away with the following steps
git reset --soft master # move branch pointer to master, all changes between your branch and master (theoretically speaking, all changes related to your feature _only_ will be in index
git commit -m "My feature"

而已。


推荐阅读