How to Modify the Last Unpushed Git Commit Message?

If the commit you want to amend only exists in your local repository and has not yet been pushed, then on the command line navigate to the repository that contains the commit, and use the git commit --amend command like so:

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

You can also edit the commit message in your text editor if you use the command without the -m flag. For example:

git commit --amend

This would modify the commit message for the most recent unpushed commit.

Please be aware that this would also commit any staged changes.


This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.