Accidentally pushed commit: change git commit message

前端 未结 4 1473
抹茶落季
抹茶落季 2020-11-28 19:43

In my local repo I have one commit with an incorrect commit message.

I\'ve already published the incorrect commit message with git push.

Now the

4条回答
  •  青春惊慌失措
    2020-11-28 19:51

    Easiest solution (but please read this whole answer before doing this):

    1. git rebase -i
    2. In the editor that opens, change pick to reword on the line for the incorrect commit.
    3. Save the file and close the editor.
    4. The editor will open again with the incorrect commit message. Fix it.
    5. Save the file and close the editor.
    6. git push --force to update GitHub.

    This will mean you will be publishing a modified version of a previously published repository. If anyone pulled or fetched from your repo between when you made the mistake with the incorrect commit message, and when you fixed it, then they will experience some difficulties later. So be sure you can accept this consequence before trying this.

提交回复
热议问题