What amend does
git commit --amend replaces the most recent commit with a new commit that includes whatever you have currently staged, plus an optional new message. It does not "edit" the commit; it creates a new one with the same parent and updates the branch pointer.
Three common amend scenarios
# 1. Fix a typo in the last commit message
git commit --amend -m "Fix avatar upload race condition"
# 2. Add forgotten files to the last commit
git add forgotten-file.js
git commit --amend --no-edit
# 3. Replace the staged changes entirely
git add -A
git commit --amend
The --no-edit flag keeps the existing message; without it, your editor opens.
The safety rule: never amend pushed commits
Amending rewrites history. If the original commit has been pushed and someone else has pulled it, amending forks history. The next time you push, Git will reject it; if you force-push, you destroy your collaborator's reference.
# SAFE: only you have this commit
git commit --amend
# DANGEROUS: commit is on origin and may be on others' machines
git commit --amend
git push --force # do not do this on shared branches
Force-with-lease for solo branches
If a branch is yours alone (a feature branch in a fork, say), amending and force-pushing is fine. Use --force-with-lease instead of --force; it refuses to push if someone else has updated the remote since your last fetch.
git commit --amend
git push --force-with-lease
Recovering from a bad amend
An amend is not destructive on your machine - the original commit lingers in the reflog for 90 days. Recover with:
git reflog
# find the SHA before the amend, e.g. HEAD@{1}
git reset --hard HEAD@{1}
Amend versus fixup
Amend works only on the most recent commit. To fix an earlier commit, use --fixup together with autosquash:
git commit --fixup <sha-to-fix>
git rebase -i --autosquash <sha-to-fix>^
The fixup commit is automatically reordered and squashed into the target during the rebase.
Author dates
By default, amend updates the committer date but preserves the author date. To reset both:
git commit --amend --reset-author --no-edit
The mental model
Treat amend as a "still drafting" tool. While a commit is local, amend freely. Once it is shared, treat it as published and write follow-up commits instead. That single rule prevents the vast majority of amend-related disasters.