I stupidly pushed a commit to GitHub with a very messed up commit name. How do I change this?
Does git commit --amend
still work for already pushed commit?
You can change the most recent commit message using the git commit --amend command.
It is recommended not to use amend if you have already pushed the changes to remote and other developers have already started using those changes.
git commit --amend
which will bring up your editor, or
git commit --amend -m "Your new message here"
which will allow you to specify the new message on the command line. Also possible, but more useful if you have other commits to reword
git rebase -i HEAD^ # then replace 'pick' with 'r' or 'reword' and save, editor should pop up again to edit the msg
Because this commit has a new SHA1 due to the change of the contents, you will need to force push the new reference. The force is needed because it tells git to forget about the previous commit. It's a safety measure.
git push origin your-branch-name -f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With