git commit --amend -m "<message>"

Replace the most recent commit with a new one using an updated message and staged changes.

This command is useful for quickly fixing the last commit (such as a typo in the message or forgotten files) by creating a new commit that overwrites it while keeping your history clean before pushing.

This command tells Git to modify the most recent commit instead of creating a new one, where --amend (same as -–amend if typed correctly) instructs Git to reuse the previous commit as a base and the -m "<message>" flag provides the new commit message directly from the command line instead of opening an editor; any files currently staged with git add are included in the amended commit, completely replacing the previous commit’s content and message. If no files are staged, only the commit message is changed, so you can use it both to fix commit messages and to include additional changes you forgot to commit the first time.

You can omit -m "<message>" to open the editor for the new message (for example, git commit --amend), or include only the message to change just the text while leaving the content unchanged (by running git commit --amend -m "Fixed typo in README" when nothing new is staged); paired commands like git add <file> before amending let you update what’s inside the commit, and related history-editing commands like git rebase -i HEAD~3 provide more powerful ways to rewrite older commits, while tools like git log -1 help you verify what the last commit looks like before and after the amendment.

Examples:

  • git commit --amend -m "Fix login bug handling"
  • git commit --amend -m "Update docs for v1.2.0"
Manual page
git commit
Related commands

Welcome to GitExamples!

Sign in to gitexamples