Amend the Last Git Commit: Message, Files, and Author
Learn how to use git commit --amend to change the last commit message, add forgotten files, or update the commit author without creating a new commit.
Detailed Explanation
Amending the Last Git Commit
git commit --amend lets you modify the most recent commit. You can change the message, add forgotten files, or update the author -- all without creating an extra commit.
Change the Commit Message
# Change the last commit message
git commit --amend -m "fix: correct typo in configuration"
# Open editor to edit the message
git commit --amend
Add Forgotten Files
# Stage the forgotten file
git add forgotten-file.ts
# Amend without changing the message
git commit --amend --no-edit
Change the Author
# Change the author of the last commit
git commit --amend --author="Jane Doe <jane@example.com>"
Change the Date
# Set to current time
git commit --amend --date=now --no-edit
# Set a specific date
git commit --amend --date="2025-06-15T10:30:00" --no-edit
How it Works
git commit --amend does not modify the existing commit. It creates a new commit with a new hash that replaces the old one. The old commit still exists in the reflog until garbage collection.
Important Warning
Since amending changes the commit hash, you should never amend a commit that has been pushed to a shared branch. If you have already pushed:
# Only if you are the sole person working on the branch:
git push --force-with-lease
On shared branches, create a new commit instead of amending.
Amend vs Reset --soft
Both achieve similar results, but:
--amend: Quick fix for the last commit onlyreset --soft: Can undo multiple commits and re-commit
# These produce similar results:
git commit --amend -m "new message"
# vs
git reset --soft HEAD~1
git commit -m "new message"
Use Case
Amending commits is a daily operation for most developers. The most common scenario is fixing a typo in a commit message immediately after committing. Adding a forgotten file (like a test case or configuration update) to the last commit is another frequent use. Teams that follow conventional commit standards use amend to correct improperly formatted messages before pushing.