Gitflow
🥞Squash 5 Commits Into OneMedium+500 XP
Scenario reference

Squash 5 Commits Into One: the situation, step by step

The situation

Your PR has 5 commits: 'wip', 'wip2', 'fix tests', 'lint', 'finally'. Reviewers want one clean commit.

`git reset --soft HEAD~5` rewinds the branch pointer but leaves all five commits' changes staged — one `git commit` then replaces them.

Medium · 4 steps · +500 XP

What you will practice

This scenario walks through 4 steps, in order:

  1. 01Rewind the last 5 commits, keeping their changes staged
  2. 02Commit all of it as one reviewable change
  3. 03Verify the new history
  4. 04Force push the squashed branch
Reveal the step-by-step commands

Try the terminal first — you learn more by doing. When you want to check yourself, here is the command for each step.

  1. 1. Rewind the last 5 commits, keeping their changes staged
    git reset --soft HEAD~5
  2. 2. Commit all of it as one reviewable change
    git commit -m "feat: complete feature x"
  3. 3. Verify the new history
    git log --oneline
  4. 4. Force push the squashed branch
    git push --force-with-lease

Key takeaway

Soft-reset + commit is the editor-free squash: same result as `pick` + four `squash` lines, no rebase todo list to edit.