Git Squash Commits
Steps:
- Choose starting commit / the number of commits you want to combine
- You can run
git log --oneline
to see all commits in a short version git rebase --interative $valueFromAbove
- Commits will be shown in the order: Oldest First
- Change the word pick to s so that those commits can get squashed
- Next will show the editor message, enter in your new message
- Push your git changes
Examples
Squash the last 3 commits
git rebase --interactive HEAD~3
git push --force-with-lease
Squash all commits AFTER $commitHash
till now
git rebase --interactive $commitHash
To squash everything just do…
git reset $(git commit-tree HEAD^{tree} -m "Initial commit.")
References:
- https://www.internalpointers.com/post/squash-commits-into-one-git