Amending Commits (--amend)
git commit --amend is the tidy-up command for your last commit. It replaces that commit with a new one — same parent, but with whatever message, files, or metadata you just changed. The original commit becomes unreachable and disappears from normal git log output (though the reflog still has it).
What --amend actually does
Amend creates a new commit and moves the branch pointer
Before: A ─ B ◀── main
▲
HEAD
git commit --amend
A ─ B' ◀── main
▲
HEAD (B is now unreachable; B' has a new SHA)Recipe 1: change just the message
Fix a typo in the last commit message
# Opens your editor with the existing message pre-filled git commit --amend # Or set the new message inline git commit --amend -m "Fix login validation regex"
Recipe 2: add a forgotten file
Tack a file onto the last commit, keep the message
git add forgotten.test.js git commit --amend --no-edit # The file is now part of the previous commit; message unchanged.
Recipe 3: replace the entire commit content
Restage, then amend
# You realised the staged content was wrong git restore --staged . # Re-add what you actually want git add src/correct-file.js git commit --amend --no-edit # The previous commit is replaced; same message, new content.
Changing the author
Fix attribution
git commit --amend --author="Alice Smith <alice@example.com>" # Also opens the editor — pass --no-edit if the message is fine
Changing the timestamp
Backdate or update the date
# A specific moment git commit --amend --date="2026-05-19T10:00:00" # Reset the author date to right now git commit --amend --date="now" --no-edit
Inspecting before and after
Confirm the amend
git log -1 --pretty=fuller
# commit b3f4a2c... (HEAD -> main)
# Author: You
# AuthorDate: ...
# Commit: You
# CommitDate: ...
git reflog
# b3f4a2c HEAD@{0}: commit (amend): Fix login validation regex
# 9c1a2b3 HEAD@{1}: commit: Fix logn vlaidation regex ← originalThe history-rewriting catch
The post-amend push dance
# Amended a commit that was already pushed? git push --force-with-lease # --force-with-lease refuses to overwrite if origin advanced since # your last fetch — safer than plain --force.
Amend only works on the LAST commit
To fix an older commit, use interactive rebase with the fixup workflow: make a tiny fix commit, then git rebase -i to fold it into the older commit.
The fixup recipe for older commits
# Make a fixup commit targeting the old commit git add forgotten.js git commit --fixup=9c1a2b3 # Then squash it into place git rebase -i --autosquash 9c1a2b3~1 # The editor opens with the fixup commit already marked 'fixup' # Save and close; the fixup merges into 9c1a2b3 with no message edit.
When NOT to amend
The commit was merged into main or any shared branch — amend would create divergent history. Use
git revertinstead.You are mid-merge or mid-rebase — finish the operation first.
You actually want a separate commit for the new work — amend is for tidy-ups, not for piling unrelated changes into the last commit.