假设我有一个commit已经push到远端了,现象我想加一个新的commit,并且合二为一后,在push到远端,我可以这样做:
<make change>
git commit -a
git rebase -i HEAD~2
这时候编辑界面打开,注意是倒叙的,旧的在上,新的在下。
保留最上面一个pick,其余pick都改成s。保存文件退出。
这时候,进入第二个编辑界面,组织一下语言,把commit message重新写一下。
保存退出。
Push到远端:
git push origin +<branch name>
还有一种方法,假设最近的3个commit需要压缩成1个,可以这样:
git reset --soft HEAD~3 (或者 git reset --soft commit-hash-just-before-the-third-one)
git commit
git push origin +<branch name>
qu'z
参考
https://www.internalpointers.com/post/squash-commits-into-one-git
https://stackoverflow.com/questions/5667884/how-to-squash-commits-in-git-after-they-have-been-pushed
https://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git