Cheat Sheets · Git Cheat Sheet · Git Amend the Last Commit
Git Amend the Last Commit
git commit --amend -m "new message"Rewrite just the message
git add forgotten.txt && git commit --amend --no-editFold a forgotten file into the commit, keep the message
git commit --amend --reset-authorUpdate the author timestamp/name to now
Amend patterns
| Command | Effect |
|---|---|
git commit --amend -m "new message" | Rewrite just the message |
git add forgotten.txt && git commit --amend --no-edit | Fold a forgotten file into the commit, keep the message |
git commit --amend --reset-author | Update the author timestamp/name to now |
If the commit was already pushed
| Command | Effect |
|---|---|
git push --force-with-lease | Force-push, but abort if someone else pushed in between (safer than --force) |
git push | Rejected — a rewritten commit has a different SHA, the remote wants a force |
Amend replaces the last commit with a corrected version — same changes plus whatever you fix up. It is the tidy alternative to "oops" commits.
Related Git recipes
FAQ
I amended a pushed commit — now what?
You rewrote history: push with --force-with-lease (never bare --force) and warn collaborators to rebase their local copies. On protected branches, prefer a follow-up fix commit.
Does amend change the commit date?
The author date is kept by default; the committer date becomes now. Add --reset-author if you want both refreshed.
Amend vs fixup?
--amend fixes the TOP commit interactively. For older commits, use git rebase -i and mark commits as fixup/squash.
Stop memorizing — build it interactively
Generate amend & push commands in the Git BuilderFull reference: Git Cheat Sheet