Loading lessons...
Git Amend
Git Amend
git commit --amend lets you fix the last commit instead of making a new one.
Fix the commit message
Forgot to spell something right in your latest message?
git commit --amend -m "Fixed message"
This replaces the last commit's message with the new one.
Add forgotten changes
If you forgot to stage a file before committing:
git add missing-file.txt
git commit --amend
The missing file gets added into the last commit, so it becomes one complete commit instead of two.
Important warning
Amend rewrites history. The old commit is replaced by a new one with a new hash. This is fine for local, unpublished work, but do not amend commits you already pushed, because everyone else has the old version.
TL;DR
git commit --amendedits the most recent commit.- Use
-mto fix the message. - Stage files first, then amend to add them.
- Amending rewrites history, so avoid it on pushed commits.