问题
I did a Git commit and push, but wrote the totally wrong thing in the comment.
How do I change the comment? I have already pushed the commit to the remote.
回答1:
git commit --amend
will allow you to edit the commit message.
If you already pushed that commit, you need to run git push --force
. Only do that if you are sure nobody pulled it yet!
If people pulled the commit from your repo, simply leave the message as it is.
回答2:
If you wrote the wrong thing and the commit has not yet been pushed, you can do the following to change the commit message:
$ git commit --amend
This will open your default text editor, where you can edit the message. On the other hand, you can do this all in one command:
$ git commit --amend -m 'xxxxxxx'
If you have already pushed the message, you can amend the commit and force push, but this is not recommended.
To force push : git push --force
来源:https://stackoverflow.com/questions/10153760/edit-an-incorrect-commit-message-in-git-that-has-already-been-pushed