Merging multiple commits into one is called “squashing” in Git.
If you have a number of commits you recently made but wish to squash them into one clean commit, use this command:
git rebase --interactive HEAD~5 //squash my last 5 commits into one
If done from the command prompt, you will be brought into VI editor to pick which commits you want. Change the word “pick” to now say “squash”.
Leave the top most commit as “pick” as this will be the remaining commit.
pick 2cf5b9aa New feature implemented --- leave this one line as pick
squash aa0ce6eb Updated yarn packages
squash 3270667d Fix in preparation of new feature
squash 1b903923 Developed new feature partway but not working yet
To save and apply changes press Escape, then colon “:x”
If you pressed escape accidentally but want to keep editing, press “i” to go back to edit mode.
If you want to squash all recent commits up to a specific commit, use:
git rebase --interactive 1b903023 // the last number is the commit hash
git rebase -i 1b903023 // short form of same command