Git Commit --amend

Quick reference for git commit --amend command

Git Commit --amend

The git commit --amend command allows you to modify the most recent commit. It's the quickest way to fix mistakes in your last commit.

Basic Usage

# Change commit message
git commit --amend -m "New message"

# Add files to last commit
git add forgotten-file.js
git commit --amend --no-edit

# Open editor to modify message
git commit --amend

Common Use Cases

Fix Typo in Message

git commit --amend -m "Fix user authentication bug"

Add Forgotten Files

git add missing-file.js
git commit --amend --no-edit

Update Last Commit

git add updated-code.js
git commit --amend -m "Complete feature implementation"

Important Notes

  • ⚠️ Never amend commits that have been pushed to shared repositories
  • Always test after amending
  • Use git reflog to recover if you make mistakes

Options

  • --no-edit: Don't change the commit message
  • --author="Name <email>": Change commit author
  • --date="date": Change commit date

Free Resources