bashbeginner

Git Amend and Fixup Commits

Amend the last commit or create fixup commits that auto-squash during rebase.

bash
# Amend the last commit message
git commit --amend -m "feat: improved login flow"

# Amend: add forgotten files to last commit (keep message)
git add forgotten-file.ts
git commit --amend --no-edit

# Amend: change author of last commit
git commit --amend --author="Name <email@example.com>"

# --- Fixup commits (for auto-squash during rebase) ---

# Create a fixup commit that targets a specific commit
git add .
git commit --fixup=abc1234
# Creates: "fixup! original commit message"

# Auto-squash fixup commits during rebase
git rebase -i --autosquash main
# Fixup commits are automatically moved and marked as 'fixup'

# Enable autosquash by default
git config --global rebase.autoSquash true

# --- Squash commit (like fixup but lets you edit message) ---
git commit --squash=abc1234

# Amend a commit that's NOT the latest (using rebase)
git rebase -i HEAD~3
# Change 'pick' to 'edit' on the target commit
# Make your changes, then:
git add .
git commit --amend --no-edit
git rebase --continue

Use Cases

  • Fixing typos in the last commit message
  • Adding forgotten changes to recent commits
  • Organizing fixup commits before PR review

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.