Combine the last three commits into one
I have several small commits and want one clean commit.
The problem
I have several small commits and want one clean commit.
How the practice repository looked before
## main
7ab5fde wip 3 8589dda wip 2 3772ba5 wip 1 d8b58af Start
The fix
[main 5aa61ea] Add numbered lines 1 file changed, 3 insertions(+)
Check the result
5aa61ea Add numbered lines d8b58af Start
Why this works
reset --soft HEAD~3 moves the branch back three commits but keeps all the changes staged. One new commit then holds them all. This needs no editor, unlike an interactive rebase.
If this is not quite your case
To squash a different number, change the 3 in both the command and your count. If you want to choose which commits to combine and keep the others, an interactive rebase (git rebase -i) is needed, which opens an editor. If the commits were pushed, the squashed branch needs a force-push, so agree it with your team first.
Be careful: Only for commits that have not been pushed.
This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.