Gitflow
🔀Reorder Commits Before PRMedium+500 XP
Workshop
Scenario reference

Reorder Commits Before PR: the situation, step by step

The situation

You committed the refactor AFTER the feature. Reviewers want the refactor first so the feature diff is small.

Interactive rebase lets you swap commit order — but conflicts can appear.

Medium · 3 steps · +500 XP

What you will practice

This scenario walks through 3 steps, in order:

  1. 01Interactive rebase to reorder
  2. 02Inspect new order
  3. 03Force push reordered history
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. Interactive rebase to reorder
    git rebase -i HEAD~2
  2. 2. Inspect new order
    git log --oneline
  3. 3. Force push reordered history
    git push --force-with-lease

Key takeaway

Move lines up/down in the rebase editor. Resolve conflicts, --continue.