Change the most recent commit message in Git




Change latest message

Luc B.


Included a typo in your commit message? No worries, it's easy to change your last commit message, especially if you haven't yet pushed to a remote repository.

Code Example

Use the --amend flag to git commit to modify the most recent commit.

git commit --amend -m "Your new commit message"

Be careful with this command, as it doesn't just modify the most recent commit message. Rather, it deletes the most recent commit and replaces it with a whole new commit. If you've already pushed to a remote repo, you'll need to re-push with with -f flag to clear out the commit you replaced.

Warning! When running this command, if you have other staged changes in the repository, they will be added to the new commit. This is sometimes useful and sometimes a surprise. Because --amend creates a whole new commit, all staged changes will be included even if the changes weren't in the original commit.