git commit --amend: Fix Your Last Commit (Message, Files, Author)
How to use git commit --amend to fix the last commit: change the message, add a forgotten file, remove a file, or fix the author — plus why amending a commit you've already pushed needs a force push, how to do that safely, and how to undo an amend with the reflog.
git commit --amend lets you fix your most recent commit instead of adding a new "oops" commit on top. Typo in the message? Forgot a file? Amend it.
Under the hood, amend doesn't edit the old commit — commits can't be changed. It replaces it with a new one. That detail matters if you've already pushed.
Change the last commit message
git commit --amend -m "Add password reset email"
Or without -m to open your editor with the old message ready to edit. (If you land in Vim and can't get out: press Esc, type :wq, Enter. How to Exit Vim.)
Add a forgotten file
git add src/email/reset-template.html
git commit --amend --no-edit
--no-edit keeps the existing message.
Remove a file you didn't mean to commit
git rm --cached .env
git commit --amend --no-edit
--cached removes it from the commit but keeps it on your disk. Add it to .gitignore too. (.gitignore Explained)
If that file contained a secret and you already pushed, amending isn't enough — assume the secret is exposed and rotate it. (Leaked API Key: What to Do)
Fix the author
If the commit went out under the wrong name or email:
git commit --amend --reset-author --no-edit
That uses your current user.name and user.email config. Set those first if they're wrong.
If you already pushed
Because amend creates a new commit, your local branch and the remote now disagree, and a normal git push is rejected. You have to force-push:
git push --force-with-lease
--force-with-lease is the safe version: it refuses if someone else pushed in the meantime, instead of silently deleting their work.
Only do this on branches nobody else is using. Never amend and force-push a shared main. On a shared branch, make a new commit instead. (Git Push Rejected)
Undo an amend
Amended the wrong thing? The old commit still exists for a while. Find it in the reflog:
git reflog
a1b2c3d HEAD@{0}: commit (amend): Add password reset email
9f8e7d6 HEAD@{1}: commit: Add pasword reset email
Go back to it:
git reset --soft HEAD@{1}
Fixing older commits
--amend only touches the latest commit. For older ones, use interactive rebase (git rebase -i) or git commit --fixup with git rebase --autosquash. (Git Squash Commits)
The summary
git commit --amendreplaces your last commit with a fixed version.-m "..."for the message,--no-editafter adding files.- Already pushed?
git push --force-with-lease, and only on your own branch.
EasySpawn works with GitHub as the home of your code, and Claude Code commits on branches from its server — so fixing up a commit before review never touches main. See how it works or join the waitlist.
Related: Git Reset vs Revert · Git and GitHub for Beginners · Claude Code Git Workflow · Git Cherry-Pick
Keep reading
"Your Branch Is Behind 'origin/main'": What It Means and What to Do
"Your branch is behind 'origin/main' by 3 commits, and can be fast-forwarded" means the remote has commits you don't have yet. What ahead, behind and diverged mean in git status, how to update safely with git pull, and what to do when you're both ahead and behind.
What Is Windsurf? The AI Code Editor, Now Called Devin Desktop
Windsurf was an AI-first code editor built on VS Code, known for its Cascade agent and Tab completions. Cognition bought it in 2025 and renamed it Devin Desktop in June 2026. What it is, what changed, how it compares with Cursor and Claude Code, and what existing users should know.