This is a quick post for those situations where you just pushed a commit to your branch and then realized the commit message is not clear, or there's some misspelling. Whatever is the reason you want to edit it, here are two quick steps.
Make sure you're in the intended branch and first run:
git commit --amend -m "Your new commit message"
Then run:
git push --force
Done.
If you run git log
you'll be able to check your updated commit message.
Donโt amend public commits
"Amended commits are actually entirely new commits and the previous commit will no longer be on your current branch. This has the same consequences as resetting a public snapshot. Avoid amending a commit that other developers have based their work on. This is a confusing situation for developers to be in and itโs complicated to recover from."
(Atlassian's tutorial)
See more
Read the GitHub docs for more information or this tutorial from Atlassian.
Top comments (3)
Bookmarking this one to remember in the future.
Also, a question: Do you have to use
--force
when you push because of the amendment?thanks
@raddevus In the case you already pushed the branch, yes. Because you're rewriting the history.
Thanks for taking time to answer. I thought it might be something like that.
Great to have this info for future use. ๐๐ฝ