How to Edit the Last Commit in Git (git commit --amend)
git commit --amend replaces the most recent commit with a new one, letting you fix its message or add forgotten changes.
Published September 27, 2026
git commit --amend replaces the most recent commit with a new one, letting you fix its message or add forgotten changes.
Key points
- Stage any additional changes with git add first, then run git commit --amend to fold them into the previous commit
- This rewrites the commit hash — never amend a commit that has already been pushed and pulled by others
- Use --no-edit to keep the existing commit message while still amending the staged content
Example
git commit --amend -m "Corrected commit message"