DEV Community

Cover image for How to change the last commit message in Git?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

How to change the last commit message in Git?

Originally posted here!

To change the last commit message in git, you can add the --amend flag to the git commit command along with the new commit message.

# Change last commit message
git commit -m "New commit message" --amend
Enter fullscreen mode Exit fullscreen mode

This will only change the most recent or the last commit message.

To push the new commit to the remote branch or the repository you have to force push the commits using the --force flag in the git push command, this is because the commit id of the newly changed commit message (or the SHA signatures) will be different. To do that you can do like this,

# Change last commit message remotely
# by force pushing the commits
git push origin branch-name --force
Enter fullscreen mode Exit fullscreen mode

Caution: Force pushing the commits may make some inconsistencies if the same branch is being used by other users.

Feel free to share if you found this useful 😃.


Top comments (0)