Skip to content

Squashing Commits

Fatema Boxwala edited this page Mar 3, 2016 · 4 revisions

If you find yourself on this page, someone has probably told you yo "squash your commits."

All this means is that you have a lot of commits for a task that could probably have been accomplished by one commit. In order to squish all your commits into one commit all you have to do is the following:

git log --format=oneline

This will print the commit history with the hex of each commit. Find the hex value of the commit you would like to squish all the ones above it into and hit q to exit the log. Then:

git rebase -i c9dq3v

This will open up a text editor listing all the commits up until the commit with hex value c9dq3v. Put a p in front of the commit you would like to keep and an s in front of all the commits you want to squash into it.

Save the file, and run:

git push --force origin HEAD

To update your remote repo.