Git squash multiple commits into one

If you ever have a scenario where you have to make a lot of changes to a branch but commit regularly so you can go back during this process if something fails BUT when you are done as a whole none of those commits actually matter except the last one (historically it will be off no use to see what was changing between revisions) you can do this in git:

Note: Before you do this all your changes need to have been committed, make sure you have nothing staged.

git reset –soft <sha_of_initial_commit>
git commit -a –amend -m “commit message”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s