假設(shè)我有一個(gè)commit已經(jīng)push到遠(yuǎn)端了,現(xiàn)象我想加一個(gè)新的commit,并且合二為一后,在push到遠(yuǎn)端,我可以這樣做:
<make change>
git commit -a
git rebase -i HEAD~2
這時(shí)候編輯界面打開,注意是倒敘的,舊的在上,新的在下。
保留最上面一個(gè)pick,其余pick都改成s。保存文件退出。
這時(shí)候,進(jìn)入第二個(gè)編輯界面,組織一下語(yǔ)言,把commit message重新寫一下。
保存退出。
Push到遠(yuǎn)端:
git push origin +<branch name>
還有一種方法,假設(shè)最近的3個(gè)commit需要壓縮成1個(gè),可以這樣:
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