Amend the last commit

Medium risk
What do risk levels mean?
Read-only
Inspects state without changing anything.
Low risk
Reversible with a routine follow-up command.
Medium risk
Changes state; undo path documented.
Destructive
Deletes or overwrites; confirmation required.

Adds currently staged changes to the most recent commit and lets you edit its message, without creating a new commit.

gitcommitamend

Commands

Confirm which commit will be amended

git log --oneline -1

Fold staged changes into the last commit and edit its message

git commit --amend

Verification

git log --stat -1

The last commit shows the updated message and includes the added changes.

Undo

Restore the branch tip to the pre-amend commit, keeping changes staged

git reset --soft 'HEAD@{1}'

Pitfalls

  • Amending rewrites the commit; never amend a commit that is already pushed to a shared branch.
  • Only staged changes are added; run git add first for anything currently unstaged.

Related