~ 2 min read

Ammend/Change Previous Git Commit Message

If you need to change/amend a text comment for one of previous commits, it's possible and fairly simple actually. Git allows to do that.

First, you need to issue a rebase command in interactive mode for any number of previous commits. For example:

$ git rebase -i HEAD~5

the above command will let you work with 5 previous commits. You can do various changes for the commits as Git does not have the SVN approach of set in stone commits. But if you just want to change the commit message for one of the commits, it's very simple.

After you issues the rebase in interactive mode command, a default configured editor should open with the list of commits that you specified in the command. If it's ~5 then last 5 commits will be there.

Just change the "pick" to "reword" at the commit you want to update and and then save the file and a new editor window should pop with the old commit message letting you change it to the right one. Change it and save and you should be all set.

***Note that the commits appear in a reverse chronological order in the list so if you have commits with the same message be careful. But of course you can always check yourself with the commit hash.

UPDATE

Note that if you just want to edit the last commit message, it's easier to just fire

$ git commit --amend