Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you rename a Git commit pushed to GitHub?

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?

like image 865
adit Avatar asked Jul 22 '12 19:07

adit


People also ask

Can you rename a commit on github?

You can change the most recent commit message using the git commit --amend command.

Can I amend already pushed commit?

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.


1 Answers

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 
like image 136
Adam Dymitruk Avatar answered Sep 24 '22 13:09

Adam Dymitruk