I actually want to squash around 5-6 commits in a single commit. What is the best option I have in this case?
Asked
Active
Viewed 492 times
-1
-
1I would do `git rebase -i HEAD~6` and mark the commits as `squash` or `fixup`. – 0x5453 Aug 19 '21 at 21:03
-
https://stackoverflow.com/search?q=%5Bgit%5D+squash+last+commits – phd Aug 19 '21 at 22:04
1 Answers
3
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'

Etienne Laurin
- 6,731
- 2
- 27
- 31