Squash my last X commits together using Git

前端 未结 30 3391
醉酒成梦
醉酒成梦 2020-11-21 05:17

How can I squash my last X commits together into one commit using Git?

30条回答
  •  盖世英雄少女心
    2020-11-21 05:29

    Simple one-liner that always works, given that you are currently on the branch you want to squash, master is the branch it originated from, and the latest commit contains the commit message and author you wish to use:

    git reset --soft $(git merge-base HEAD master) && git commit --reuse-message=HEAD@{1}
    

提交回复
热议问题