Skip to content

Squashing commits and force pushing them to git

February 21, 2013

Suppose you want to the past three commits into one commit.

do a
$ git rebase -i HEAD~3


$ git rebase -i <sha>

Where sha is the the SHA of the 4th commit in the log.

This wil then open up the default editor window with the relevant commits (the past three in this case) and the actions to perform. Note that the commits with be in an order opposite to that which git log shows. So they will be ordered with the oldest first.

You can set the actions you want on each commit. ‘pick’ ‘squash’ ‘squash’ will squash the newer commits into the older one.

You should also be asked to modify commit messages.

Now when you are done, if you have previously committed to the git repository, you have changed history and now you need to force your push.

$ git push origin <branchname> -f

Learnt from here: but just wanted to make a few personal comments.


From → Uncategorized

Leave a Comment

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: