Interview Prep/Git & GitHub/Rebase, Cherry-pick and History Rewriting

You want the database migration commit to come before the code that uses it.

BeginnerScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → Commit order is wrong, though the tree content is fine.

What I'd do →

  1. git rebase -i HEAD~5.
  2. Move the pick line for the migration above the dependent commit.
  3. Resolve conflicts if both touch the same files, then git rebase --continue.
  4. Run tests at each step: git rebase -i --exec "make test" HEAD~5.

Why → Each commit should build and pass tests on its own, so bisect stays reliable.

Interview tip → Reordering conflicts are a sign that the commits are not truly independent.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting