Interview Prep/Git & GitHub/Undoing Mistakes

You made a typo in your last commit message and have not pushed.

BeginnerScenarioUndoing Mistakes
Answer

Situation read → Only the message needs change.

What I'd do →

  1. git commit --amend -m "Fix login redirect for SSO users".
  2. To also add a forgotten file: git add file && git commit --amend --no-edit.

Why → Amend replaces the last commit with a new one (new SHA). That is safe only while nobody else has the old one.

Interview tip → If it is already pushed to a shared branch, do not amend; add a follow-up commit instead.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes