Fixing a mistake in an earlier commit is done with an interactive rebase, which lets you pause at that specific commit, amend it, and then replay the remaining commits on top of the correction.
A developer notices commit three of the last five had a typo in a variable name; they run git rebase -i HEAD~5, mark that commit edit, fix the typo, run git commit --amend, then git rebase --continue to reapply the later commits cleanly.
git rebase -i HEAD~5
# mark the target commit as "edit", save and close
# make the fix
git add .
git commit --amend
git rebase --continueA concise interview answer is
I'd run an interactive rebase with git rebase -i, mark the problem commit as edit, fix it, and amend it with git commit --amend, then continue the rebase to replay the rest on top. It's a clean way to fix history, but only safe on commits that haven't been shared yet.
Last updated: 11 November 2026
Previous question: You need changes from a teammate's branch in your feature branch. How would you bring them in?
Next question: What strategies would you employ to review a large number of pull requests effectively?