How to edit/amend commit messages for commits previous to the last in Git?

334 views Asked by At

As shown on this popular answer in SO, when I need to edit/correct the message for the last commit, I do:

git commit --amend -m "New commit message"

But what am I supposed to do when I want to amend commit messages for commits previous to the last one? For instance, the 14th last commit - also considering that commits have not been pushed to remote?

Is there a way of doing this without resetting previous commits? Would rebase be the right thing to do in this case?

1

There are 1 answers

4
Ayush Chaudhary On BEST ANSWER

You would need interactive rebasing as mentioned here: How to modify a specified commit in git?

The difference being, instead of edit you'll just want to reword the commit in question since you just want to edit the commit message.

Here's another useful resource: https://help.github.com/articles/interactive-rebase

edit: reword only works on versions 1.6.6 or newer as noted by the OP.