11. Commit Message
11.1 Basics
Often, we just need to re-word a commit message.
if it is just the commit message of the latest
commit, we can use --amend
option as below
#git commit --amend -m 'new commit msg'
If it is a commit msg of an arbitrary commit, then we need to use rebase
command
git rebase -i <AFTER_THIS_commit_OR_branch_OR_tag>
Then git gives the option to reword
, select all commit hashes that we want to reword.
Then another editor will be given, then cleanly updated commit msg. That is all.
We need to push using force
push. This is a rewrite of history, hence --force
push is necessary.
git push --force <remote_name> <branch>
In fact, we can also use above command to reword last commit msg.
git rebase -i HEAD~1
Then do the reword
action.
I feel above command (rebase
) is better than --amend
option since above command keep refreshing my memory on
rebase
command. Also, I don't need to remember --amend
option which is specific.