Squash my last X commits together using Git

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

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

30条回答
  •  一个人的身影
    2020-11-21 05:49

    Based on this article I found this method easier for my usecase.

    My 'dev' branch was ahead of 'origin/dev' by 96 commits (so these commits were not pushed to the remote yet).

    I wanted to squash these commits into one before pushing the change. I prefere to reset the branch to the state of 'origin/dev' (this will leave all changes from the 96 commits unstaged) and then commit the changes at once:

    git reset origin/dev
    git add --all
    git commit -m 'my commit message'
    

提交回复
热议问题