[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.

Advertisements