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

An older commit message is poor and the branch is private. How do you reword it?

BeginnerScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → Only the message of a past commit needs to change.

What I'd do →

  1. git rebase -i HEAD~6.
  2. Change pick to reword for the target commit.
  3. Save, then edit the message in the editor that opens.
  4. git push --force-with-lease if the branch was pushed.

Why → Reword replays that commit with a new message and updates descendants.

Interview tip → For only the last commit, git commit --amend is enough.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting