Git - 如何用任何其他提交压制最后一个提交



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

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

我想用 5 压扁 3 以便:

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,例如:

  • 4 3
  • 4 3 2
  • 4 3 2 1

你可以通过交互式变基来做到这一点。

只需在 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

但是,由于您更改了顺序,可能会发生冲突,有时不值得重写历史......

最新更新