[Git] Squashing commits

Taken from here https://ariejan.net/2011/07/05/git-squash-your-latests-commits-into-one/

Summing up:

git rebase -i HEAD~3

What we’re doing is rewriting the history to make 3 commits become a single one.
You can replace 3 by any number of commits to rewrite

pick f392171 Added new feature X
pick ba9dd9a Added new elements to page design
pick df71a27 Updated CSS for new elements

write the word “squash” in the ones that will be squashed

pick f392171 Added new feature X
squash ba9dd9a Added new elements to page design
squash df71a27 Updated CSS for new elements

Then Ctrl+X (if using nano on Linux)
Now another screen will appear, customize the commit message for all squashed commits and Ctrl+X again.

Advertisement

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 )

Connecting to %s