Skip to main content
Code and think

GIT Edit commits aka squash, drop ...

To squash commits in git you can use git rebase -i HEAD~2. The number depends on the number of commits you want to adjust. If you want to pick the commit use p, to drop it use d or s to squash. The window with a list of commits will present other possible operations as well.

Reference

You can also modify not last commit. To do that use e or edit for the commit you want to edit. Git will checkout the commit for you and you can edit it with --amend parameter.

For example, find the SSH of a commit you want to edit.

git rebase --interactive '813b9b4e^'

You must put the caret "^" sign, so that it will go to one commit before yours.

Then you can edit the commit like:

git commit --amend --no-edit

Skip --no-edit if you want to edit commit message.

When you are done conclude with:

git rebase --continue

Note, that the commit SSH will be modified. The same will also happen for all subsequent commits.

Reference