🎓 A1Learner
🔍
0 of 50 lessons completed

Amend a Commit

Amend fixes the last snapshot. It changes the message, the files, or both, and keeps one snapshot instead of two.

Fix the file and amend

Sugar joins the recipe. Amend folds it into the last snapshot.

$ git add recipe.txt
$ git commit --amend -m "Add pancake recipe with sugar"

The log shows one snapshot

The recipe snapshot has a new hash and a new message.

$ git log --oneline

Example

$ git commit --amend -m "Add pancake recipe with sugar"
$ git log --oneline

Key points

  • Amend only touches the newest commit.
  • Stage the fix first, then amend.
  • Amend rewrites the snapshot with a new hash.
  • The old snapshot is gone from the log.
  • Use amend for small fixes right after a commit.
  • Never amend a commit you already shared.
  • The word shared means sent to another repository.

Here, amend rewrites the newest snapshot. The log still holds three snapshots, not four. The old recipe snapshot is gone.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does --amend change?