How to squash commits on git branch
When submitting a pull request, it's important that you squash your commits to keep our repository concise and clean.
You will need to use VIM to do this.
Make sure your branch is up to date with the master branch.
git rebase -i master.
- VIM will be opened
- You should see a list of commits, each commit starting with the word "pick".
son the console -- This will bring you to insert/edit mode of VIM
- Make sure the first commit says "pick" and change the rest from "pick" to "squash". -- This will squash each commit into the previous commit, which will continue until every commit is squashed into the first commit.
- Save and close the editor by pressing
- It will give you the opportunity to change the commit message.
- Non-commented lines will appear as commit messages. Commented lines (preceded with #) will not appear on the commit message.
- Save and close the editor again by pressing
- Then you have to force push the final, squashed commit:
git push -f.