CommandGit

Change the last commit message

Rewrites the most recent commit's message in place without creating a new commit, as long as it hasn't already been pushed and shared.

Last updated

Commandgit
git commit --amend -m "New message"

How it works

--amend doesn't create a new commit on top of the last one — it replaces the most recent commit entirely, combining whatever is currently staged with a new message. -m supplies that message directly on the command line instead of opening your configured editor prefilled with the old text.

Because the message is part of what git hashes to identify a commit, amending it produces a brand-new commit hash even though the content is otherwise the same — from git's perspective it genuinely is a different commit, not an edited version of the old one.

Watch out for

  • Never amend a commit that's already been pushed and possibly pulled by someone else — the new hash means your branch and theirs have now diverged; either don't amend shared commits, or coordinate a force-push (git push --force-with-lease) if everyone agrees.
  • Omit -m to open your editor prefilled with the existing message instead of replacing it outright — useful when you want to tweak wording rather than retype the whole thing.
  • --amend also folds in whatever is currently staged with git add, not just the message — if unrelated changes happen to be staged, they'll silently become part of the amended commit too.

Related in Commands