Interview Q&A / Git & GitHub

IntermediateQuick answer1 min readUpdated 3 Oct 2026

How do you fix the message of a commit that is not the latest?

SHORT ANSWER

Run git rebase -i, mark that commit as reword, save, and edit the message. Only do this for commits not yet shared, since every commit after it also gets a new hash.

Explain it simply

Amend only handles the last commit. For one further back, you open the rebase list and tell Git which message to edit.

Start git rebase -i HEAD~5 so the target is in the list. Change pick to reword on that line, save, and Git pauses on that commit to let you type the new message. Then it replays the rest. All later commits get new hashes. For a commit already pushed to a shared branch, leave it alone or add a note in a follow-up commit.

Example

bash
git rebase -i HEAD~5
# change: pick 8a9b0c1 wip   ->   reword 8a9b0c1 wip
# editor opens, type: Add OTP resend button
git push --force-with-lease

What to say in the interview

"I use git rebase -i to reach the commit, change pick to reword, and type the new message. Later commits are rewritten too, so I only do it on unshared work and push with --force-with-lease."

#git#commit-message#rebase

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.