How to change the commit message of a commit in the history (not HEAD)?

A commit is not the HEAD now. and git commit --amend will not work for it.

How to change its commit message?

asked Dec 11, 2014 by Eric Z Ma (44,280 points)

1 Answer

Best answer

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.

answered Dec 11, 2014 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost