Gitflow
🧹Pre-PR History CleanupMedium+500 XP
Scenario reference

Pre-PR History Cleanup: the situation, step by step

The situation

11 commits including 'WIP', 'fix typo', 'actually fix it'. Tech lead won't approve.

Squash 11 messy commits into one clean commit — no rebase editor needed.

Medium · 5 steps · +500 XP

What you will practice

This scenario walks through 5 steps, in order:

  1. 01View messy history
  2. 02Rewind all 11 commits, keeping every change staged
  3. 03Record them as one clean commit
  4. 04Force push clean history
  5. 05Verify
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. View messy history
    git log --oneline
  2. 2. Rewind all 11 commits, keeping every change staged
    git reset --soft HEAD~11
  3. 3. Record them as one clean commit
    git commit -m "feat: dashboard"
  4. 4. Force push clean history
    git push --force-with-lease
  5. 5. Verify
    git log --oneline

Key takeaway

11 → 1 clean commit. `git reset --soft` rewinds the branch pointer while leaving every change staged, so the follow-up `git commit` replaces the whole run — the editor-free equivalent of pick + squash.