How to squash the last N commits into a single commit in git?

0

Issue

I actually want to squash around 5-6 commits in a single commit. What is the best option I have in this case?

Solution

With the most recent commit checked out, do a soft reset to your desired parent commit. If the commits are linear, The parent of the last N commits is HEAD~N. For example, to combine the last five commits:

git reset --soft HEAD~5

Optionally, make sure you’ve got the right changes with git status or git diff.

Then create the new commit:

git commit -m 'five combined commits in one'

Answered By – AtnNn

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More