Git Amend
Git amend replaces your most recent commit with a new one, letting you fix a typo'd message or slip in a forgotten file change without cluttering history with a follow-up commit.
What Amend Really Does
git commit --amend does not edit the previous commit in place — it creates an entirely new commit that replaces it, combining whatever is currently staged with the contents of the old commit, and lets you reuse or rewrite its message. Because it's a replacement rather than a true edit, the old commit's hash disappears from your branch and a new hash takes its place. That's the detail that makes amend perfectly safe on unpushed work and risky on anything already shared.
Fixing a Commit Message
The most common use case is realizing your last commit message has a typo or doesn't describe the change well. Running amend with no staged changes and a new -m message swaps in the corrected text while leaving the file changes untouched.
Fix a typo in the last commit message
$ git log --oneline -1
4e8a012 (HEAD -> main) Fix bg in header render
$ git commit --amend -m "Fix bug in header render"
[main 8b1f5c9] Fix bug in header render
Date: Thu Jul 16 10:22:03 2026 +0530
1 file changed, 4 insertions(+), 1 deletion(-)
$ git log --oneline -1
8b1f5c9 (HEAD -> main) Fix bug in header renderAdding a Forgotten File to the Last Commit
If you commit and then notice you forgot to stage a file that belonged with that change, stage it and amend without passing a new message — Git will reopen your editor with the old message pre-filled, or you can keep it as-is with --no-edit.
Add a forgotten file, keep the same message
$ git status
On branch main
Untracked files:
src/utils/formatDate.js
$ git add src/utils/formatDate.js
$ git commit --amend --no-edit
[main 2c9e441] Fix bug in header render
2 files changed, 15 insertions(+), 1 deletion(-)Amending Further Back With Rebase
Amend only ever touches the single most recent commit. If the commit you need to fix is two or three commits behind HEAD, plain amend can't reach it — you need an interactive rebase, marking the target commit as 'edit', making your fix, and continuing.
Amend a commit that isn't the most recent one
$ git rebase -i HEAD~3
# mark the target commit's line as 'edit', save and close
Stopped at 6a3f120... Add pricing table
$ echo 'fixed content' >> src/pricing/table.js
$ git add src/pricing/table.js
$ git commit --amend --no-edit
$ git rebase --continue
Successfully rebased and updated refs/heads/main.- git commit --amend -m "new message" — replace both message and staged changes
- git commit --amend --no-edit — replace the commit's contents, keep the same message
- git commit --amend --author="Name <email>" — correct the recorded author
- git rebase -i HEAD~n then mark 'edit' — amend a commit further back in history
- git push --force-with-lease — required to update a remote after amending a pushed commit
Amend vs a Fresh Commit
Used well, amend keeps your commit history tidy: one commit per logical change, with an accurate message, instead of a trail of "oops" and "fix previous commit" entries. The tradeoff is that it's a rewriting operation, so the same sharing rule that applies to reset applies here too.
Exercise: Git Amend
What does `git commit --amend` primarily let you modify?