Gitflow
✏️Fix a Commit Message Mid-BranchEasy+350 XP
Scenario reference

Fix a Commit Message Mid-Branch: the situation, step by step

The situation

Three commits ago you wrote 'fix bug' but it was actually a feature. The whole team uses conventional commits.

Rewind past the badly-named commit, replay it, amend its message, then replay the two that followed.

Easy · 7 steps · +350 XP

What you will practice

This scenario walks through 7 steps, in order:

  1. 01Bookmark the tip before rewriting anything
  2. 02Rewind to just before the badly-named commit
  3. 03Replay the badly-named commit
  4. 04Give it the message it should have had
  5. 05Replay the tests commit
  6. 06Replay the docs commit
  7. 07Force push the rewritten 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. Bookmark the tip before rewriting anything
    git branch backup
  2. 2. Rewind to just before the badly-named commit
    git reset --hard HEAD~3
  3. 3. Replay the badly-named commit
    git cherry-pick backup~2
  4. 4. Give it the message it should have had
    git commit --amend -m "feat: add rate limiting"
  5. 5. Replay the tests commit
    git cherry-pick backup~1
  6. 6. Replay the docs commit
    git cherry-pick backup
  7. 7. Force push the rewritten branch
    git push --force-with-lease

Key takeaway

`reword` in a rebase todo is shorthand for exactly this: replay the commit, `git commit --amend -m` a better message, replay the rest.