The Real Mistake
git add tacos.md
git commit -m "Addd taco recipe"
A real typo, and salsa.md — meant to accompany it — is still sitting there untracked.
Staging What Was Forgotten
Now it is ready to be folded into the same commit, rather than becoming its own separate, oddly-scoped one.
Fixing Both at Once
git commit --amend -m "Add taco and salsa recipes"
This genuinely replaces the previous commit entirely: the newly-staged salsa.md is included, and the message is corrected — one real, clean commit, with a completely new hash.
The One Real Rule
Amend is for commits that exist only on your machine. The moment a commit has been pushed or shared, amending it creates a genuine hash mismatch with whatever anyone else already has — that scenario is covered later, with the safe alternative (git revert).
Two real mistakes at once, which happens more often than either alone: the commit message has a genuine typo ("Addd" instead of "Add"), and salsa.md — meant to be part of the same commit as tacos.md — never got staged before you hit enter.
As long as this commit has not been pushed or shared, git commit --amend genuinely fixes both problems at once: stage the forgotten file, then amend with the corrected message. One clean commit results — no trace of the mistake remains in the history anyone else will ever see.
git commit --amend -m <message>
Replaces the most recent commit with a new one: whatever is currently staged (including anything staged since the original commit) plus the new message. Confirmed directly in this lab producing a genuinely new commit hash, since the content changed.
Takeaways
- git commit --amend -m <message> replaces the most recent commit with corrected message and/or newly-staged files
- The amended commit gets a genuinely new hash — its content is different, so its fingerprint is different
- The original, mistaken commit is no longer visible in git log after amending — it was replaced, not edited
- Amend is only safe for commits that exist solely on your own machine, not yet pushed or shared with anyone