Git - 如何将最后一次提交与任何其他提交压缩

Git - How to squash the last commit with ANY other one

考虑本地分支上的以下一系列提交:

5 Correction of something meaningless, again !
4 Business correction n°3
3 Correction of something meaningless
2 Business correction n°2
1 Business correction n°1

我想用 3 压缩 5 以获得:

4 Correction of something meaningless, squashed !
3 Business correction n°3
2 Business correction n°2
1 Business correction n°1

我可以使用交互式变基来做到这一点吗?根据我所看到的(例如:https://www.internalpointers.com/post/squash-commits-into-one-git)和到目前为止的测试,我只能通过一系列直接提交来压缩 5,例如:

您可以使用交互式变基来完成。

当 git 提示时,只需像这样重新排列行:

squash 5 Correction of something meaningless, again !
pick 3 Correction of something meaningless
pick 4 Business correction n°3
pick 2 Business correction n°2
pick 1 Business correction n°1

但是,因为你改变了顺序,可能会发生冲突,有时不值得重写历史......