edit previous commit message code example
Example 1: edit last commit message
git commit --amend -m "New commit message."
Example 2: git amend last commit message
$ git commit --amend -m "New and correct message"
Example 3: change commit message
git commit --amend
// press enter, editor would open
Example 4: git change commit message of old commit
git commit --amend -m "New commit message"
Example 5: git change commit message of old commit
Step1: git rebase -i HEAD~n to do interactive rebase for the last n commits affected. (i.e. if you want to change a commit message 3 commits back, do git rebase -i HEAD~3)
git will pop up an editor to handle those commits, notice this command:
that is exactly we need!
Step2: Change pick to r for those commits that you want to update the message. Don't bother changing the commit message here, it will be ignored. You'll do that on the next step. Save and close the editor.
Note that if you edit your rebase 'plan' yet it doesn't begin the process of letting you rename the files, run:
git rebase --continue
If you want to change the text editor used for the interactive session
Step3: Git will pop up another editor for every revision you put r before. Update the commit msg as you like, then save and close the editor.
Step4: After all commits msgs are updated. you might want to do git push -f to update the remote.