How can I squash my last X commits together into one commit using Git?
In addition to other excellent answers, I'd like to add how git rebase -i
always confuses me with the commit order - older to newer one or vice versa? So this is my workflow:
git rebase -i HEAD~[N]
, where N is the number of commits I want to join, starting from the most recent one. So git rebase -i HEAD~5
would mean "squash the last 5 commits into a new one";Sources & additional reads: #1, #2.