如何git squash

假設(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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容