How do you rename a Git commit pushed to GitHub?

GitVersion ControlGithub

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

To make changes in already pushed commit, please do that

git reset --soft HEAD~1
git add .
git commit -m "custom message"
git push -u -f origin master

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaditView Question on Stackoverflow
Solution 1 - GitAdam DymitrukView Answer on Stackoverflow
Solution 2 - GitGuruView Answer on Stackoverflow