Rebase a working branch without squashing commits by hand
Full credit to: https://blog.oddbit.com/post/2019-06-17-avoid-rebase-hell-squashing-wi/
-
Check out a new branch based on
master(or the appropriate base branch if your feature branch isn’t based onmaster):git checkout master git checkout -b work -
Bring in the changes from your messy pull request using git merge --squash:
git merge --squash my_featureThis brings in all the changes from your
my_featurebranch and stages them, but does not create any commits. -
Commit the changes with an appropriate commit message:
git commitAt this point, your work branch should be identical to the original
my_featurebranch (running git diffmy_feature_branchshould not show any changes), but it will have only a single commit aftermaster. -
Return to your feature branch and reset it to the squashed version:
git checkout my_feature git reset --hard work -
Update your pull request:
git push -f -
Optionally clean up your work branch:
git branch -D work