如何在变基期间压缩(与下一个合并)提交?

How to squash (merge with next one) commit during rebase?

这是我的伪树:

A---B---C---D (master)

我从根开始交互式变基:git rebase --root -i 并为所有提交设置 edit 命令。这是示例:

e b83fa60 Initial content (A)
e 9a82ddf Update license information (B)
e fa8cb80 Rewrite readme (C)
e 0525f07 Update email address (D)

现在我在变基期间停在了 B:

A---B---C---D (master)
    ^

此时我想 "merge" 或 "squash" B 与下一个 C 提交。我该怎么做?

git rebase --continue 将在下一个 e 提交即 C 处阻止您,然后 git reset HEAD^ && git add . && git commit --amend 会将当前(C)与之前的(B)压缩。尽管我个人会简单地继续变基并再次重做并将 C 标记为 sf - 更简单和更快。