amend commit message
The most recent commit message:
If the commit only exists in your local repository and has not been pushed to GitHub, you can amend the commit message with
git commit --amend -m 'Your new message'
(In Git, the text of the commit message is part of the commit. Changing the commit message will change the commit ID)
If you have already pushed the commit to GitHub, you will have to force push a commit with an amended message.
- Follow the steps above to amend the commit message.
- Use the
push --force
command to force push over the old commit.
Change older or multiple commit messages
git rebase -i HEAD~n
where n is the number of commits you want to look back, ex. 'git rebase -i HEAD~5'. It will open your git editor.- This will open the “commit list” file. For each commit message you want to update, replace
pick
withreword
and add the issue number, ie 'pick e499d89 work description' will become 'reword e499d89 JIRA-1234 work description' - save the file, and close it.
- In each resulting commit file, enter the issue number before the message, save and quit
- Force-push the amended commits:
git push –force
$ git log
$ git rebase -i HEAD~3
Cannot rebase: You have unstaged changes.
Please commit or stash them.
$ git push --force
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
Interactive mode
$ git rebase --continue
$ git rebase --abort
Git Editor - the default editor is vi
. Or, you can change it
git config core.editor notepad
git config core.editor emacs
Reference
Check out this tutorial for additional info.