Find the SHA of the commit you want squash to
If we want to squash all our work down to Story X, we need to go one beyond and grab the SHA from the one after the one we want to squash down to.
Cntl-v enter visual mode
Select text
c – to delete
Type what you want to appear (s)
Press ‘Esc’ x2
Add a ‘p’ to top commit (reverse order)
Save (:wq)
…
If you have a conflict, fix the conflict then…
git add . git rebase --continueIf you make a mistake
git rebase --abortIf you want to change a commit message
git commit --amendIf you want to add another author to a commit
git commit --amend --author "peter+paul " -C HEAD git commit --amend git push -fSquash specific number of commits together
If you want to squash say x3 commits together to this
git rebase --interactive HEAD~3 or git reset --soft HEAD~2 && git commit</pre> <pre>And that will produce this
So when you go ~3 it squashes three down into one. But doesn’t affect the one before it.
Rebase master
Then when ready to run master onto of your changes on your local branch.
git rebase master
Leave a Reply