交互式变基在尝试压缩提交后不断添加步骤

  • 本文关键字:添加 提交 压缩 交互式 git
  • 更新时间 :
  • 英文 :


当将我的分支重新定位以通过将它们挤压在一起来清理提交时,我的变基卡在一个循环中,不知道如何打破它。这是针对我正在处理的每个分支,而不仅仅是一个特定的分支。

例如,假设我有一个分支my-branch有三个提交

commit 1
commit 2
commit 3

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

这让我想到了交互式 git(就我而言,在崇高文本上)

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

p commit 1
p commit 2
s commit 3

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

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

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

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

如果你想在最后挤压变基,你可以跳过使用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"

就是这样。

最新更新