Gitflow
✂️Split One Commit Into TwoHard+700 XP
Scenario reference

Split One Commit Into Two: the situation, step by step

The situation

You bundled an unrelated CSS tweak into your big API refactor commit. Reviewer asks: 'Please separate these.'

Undo the commit but keep its content, then commit the two halves separately.

Hard · 6 steps · +700 XP

What you will practice

This scenario walks through 6 steps, in order:

  1. 01Undo the bundled commit, keeping its content
  2. 02Commit the API refactor on its own
  3. 03Write the CSS tweak as its own change
  4. 04Stage only the stylesheet
  5. 05Commit the CSS separately
  6. 06Confirm one commit became two
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. Undo the bundled commit, keeping its content
    git reset HEAD~1
  2. 2. Commit the API refactor on its own
    git commit -m "refactor: api"
  3. 3. Write the CSS tweak as its own change
    echo "button { padding: 8px }" > button.css
  4. 4. Stage only the stylesheet
    git add button.css
  5. 5. Commit the CSS separately
    git commit -m "style: button tweak"
  6. 6. Confirm one commit became two
    git log --oneline

Key takeaway

reset HEAD~1 → commit the first half → stage the second half → commit again. `edit` in a rebase todo drops you into exactly this state, one commit deeper in history.