A really quick step-by-step guide on how to squash Git commits to make your PRs concise, easy to read, and hence easy to review.
- Make sure your branch is up to date with the
git rebase -i main.
- You should see a list of commits, each commit starting with the word "pick".
- Make sure the first commit says "pick" and change the rest from "pick" to "squash". -- This will squash each commit into the previous commit, which will continue until every commit is squashed into the first commit.
- Save and close the editor (press
Enterkey) -- save a file and quit vim / Vi by pressing
- It will give you the opportunity to change the commit message.
- Save and close the editor again.
- Force push the squashed commit:
git push --force-with-lease origin.
Top comments (2)
After making sure your branch is up to date with the remote(origin) master branch, you can also try this:
git reset --soft origin/master
This will let you add all the changes into a single commit.
This looks like a nice short-cut if you need all changes in a single commit. ty Shankar