Edit an incorrect commit message in Git that has already been pushed

北城以北 提交于 2019-11-29 07:41:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!