git:如何将多个提交变基为一个

git: how to rebase several commits into one

这是我当前的日志,从最近的提交到最近的提交:

E   I want this message
D   I don't want this message
C   Don't want this message
B   Don't want this message
A   Want this commit separately

我想将提交 B-E 压缩为单个提交,并保持提交 A 分开,这样它看起来像这样:

F   I want this message
A   Want this commit separately

其中 F 包含从 BE 的所有更改。我试过这个:

git rebase -i A

pick A Want this commit separately
reword B I want this message
fixup C
fixup D
fixup E

它提示我输入一条提交消息,自动填充来自提交 B 的现有消息,然后失败,显示 You asked to amend the most recent commit, but doing so would make it empty.

我怎样才能得到我想要的历史?

来自

您可以:

git commit --allow-empty
git rebase --continue
git rebase -i HEAD~~
# fixup or remove second (empty) commit