How to squash commits into one


  1. use git log --online to check all your commits history in a brief form.

  2. find the hash head of the first commit you want to squash to.

  3. run git reset --soft <hash> to reset the HEAD to that commit.

  4. run git add . to add all the changes made in commits after the first one.

  5. run git commit --amend -m "new commit message" to replace the old commit message in the first commit to the new one.

    ATTENTION: In step 5, omitting --amend would result in making a new commit and squash all commits into that new one instead of the first one.

  6. run git push --force


A u t h o r: Joe
P o l i c y: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Joe !
Leave Your Comment Here
  TOC