git commit --amend rewrites the last commit. Useful for:
- Typos in the message
- A file you forgot to stage
- Removing a debugging
console.log you accidentally committed
Workflow:
# Forgot to stage utils.ts
git add utils.ts
git commit --amend --no-edit # keep message
# Or to also rewrite the message:
git commit --amend -m "feat: better message"
⚠️ Amend rewrites the commit's hash. If you've already pushed, your remote now diverges. Amend only commits that are local-only — or be ready to git push --force-with-lease.