Skip to content

Instantly share code, notes, and snippets.

@FusRoDah061
Last active November 29, 2019 12:19
Show Gist options
  • Save FusRoDah061/bc35d0a4cb5758b18a4889e1b3e8854f to your computer and use it in GitHub Desktop.
Save FusRoDah061/bc35d0a4cb5758b18a4889e1b3e8854f to your computer and use it in GitHub Desktop.
Easy squash method for squashing a lot of commits and conflict-proof
# assume starting branch is master, and we want to squash a bunch of commits from original_messy_branch
git checkout master
# create a new branch from master
git checkout -b new_clean_branch
# apply all changes from original_messy_branch to new_clean_branch either with
git merge original_messy_branch
# and then, forget the commits but have the changes staged for commit
git reset --soft master
# or
git merge --squash original_messy_branch
git commit -m "Squashed changes from original_messy_branch"
# For pull requests
# rename local original_messy_branch to something else
git checkout master
git branch -m original_messy_branch original_messy_branch_still_messy
# rename new_clean_branch to original_messy_branch
git branch -m new_clean_branch original_messy_branch
# force push original_messy_branch (former new_clean_branch)
git checkout original_messy_branch
git push -f origin original_messy_branch
# Reference:
# https://stackoverflow.com/a/44789323/9214463
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment