squash commits git
git reset --soft HEAD~3 &&
git commit
squash commits git
git reset --soft HEAD~3 &&
git commit
git squash branch
# Assuming you were branching from the master,
# you don't need to enter yourBranch into the reset step all the time:
git checkout yourBranch
git reset --soft HEAD~$(git rev-list --count HEAD ^master)
git add -A
git commit -m "one commit on yourBranch"
# Explanation:
git rev-list --count HEAD ^master counts the commits since you made your feature branch from the master, f.ex. 20.
git reset --soft HEAD~20 will make a soft reset of the last 20 commits. This leaves your changes in the files, but removes the commits.
#Usage:
# In my .bash_profile I have added an alias for gisquash to do this with one command:
# squash all commits into one
alias gisquash='git reset --soft HEAD~$(git rev-list --count HEAD ^master)'
#After reseting and committing you need to do a
git push --force
squash commits on branch
git rebase -i HEAD~20
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us