Squash multiple commits into one
Premature commits happen all the time. And often you want to squash all those premature commit into one meaningful commit to keep your commit history clean, easily readable and more meaningful. It's quite easy to squash as many commits as you want using following commands
[wpgist id="548762f6f2d66f4641a3" file="squash-commits.sh"]
In this example, git reset --soft
resets the HEAD to the provided commit number. And adds all the changed files into the stagging area then you can create one meaningful commit message for all the changed files. If you have not pushed your changes to remote in the past you do not have to use --force
flag.