How to change the commit message of a commit in the history (not HEAD)?
Posted on In QAA commit is not the HEAD now. and git commit --amend
will not work for it.
How to change its commit message?
You can use git rebase
together with git commit --amend
as follows. Assume your commit to be edited is 2b8ed
.
$ git rebase -i 2b8ed^
Change the pick
to edit
in the line contains 2b8ed.
Now, you have moved back to the commit before 2b8ed and you can do the commit message changing as before by:
$ git commit --amend
Then run:
$ git rebase --continue
This command applies the following commits automatically to the original HEAD.
Be very careful when doing this if the commit has already been pushed to a git server and is shared with others. The others may need to rebase to get the changed history.
Note: read more about rewritting history in Pro Git.