Change old commit message on Git

后端 未结 5 1128
南旧
南旧 2020-12-12 09:24

I was trying to edit an old commit message as explained here.

The thing is that now, when I try to run rebase -i HEAD~5 it says interactive rebas

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-12 09:46

    As Gregg Lind suggested, you can use reword to be prompted to only change the commit message (and leave the commit intact otherwise):

    git rebase -i HEAD~n
    

    Here, n is the list of last n commits.

    For example, if you use git rebase -i HEAD~4, you may see something like this:

    pick e459d80 Do xyz
    pick 0459045 Do something
    pick 90fdeab Do something else
    pick facecaf Do abc
    

    Now replace pick with reword for the commits you want to edit the messages of:

    pick e459d80 Do xyz
    reword 0459045 Do something
    reword 90fdeab Do something else
    pick facecaf Do abc
    

    Exit the editor after saving the file, and next you will be prompted to edit the messages for the commits you had marked reword, in one file per message. Note that it would've been much simpler to just edit the commit messages when you replaced pick with reword, but doing that has no effect.

    Learn more on GitHub's page for Changing a commit message.

提交回复
热议问题