How to Squash git commits
To “squash” commits is to take a series of commits and turn them into a single commit representing all of the changes made.
Squashing commits might be requested before allowing a PR to be merged.
To squash commits on a local branch, feature-1
:
- Make sure you’re up to date with the master branch with
git pull origin master:master
- On your feature branch, run interactive rebase with
git rebase -i master
- Change
pick
s tosquash
s. - Save and close
- Change the commit message to be descriptive of your new commit.
- Save and close again.
- Do a force push as safely as you can with
git push --force-with-lease