Amend Git Message
Modify git commit message
- switch git commit editor from
NANO
toVIM
:git config --global core.editor vim
- Edit the most recent commit message:
git commit --amend
orgit commit --amend -m "New commit message."
- before changing commit message, you can also add other changes via
git add <files>
- Edit historical commit message:
git rebase -i HEAD~N
(modify \(N^{th}\) latest commit message) orgit rebase -i <commit id>
(you can only modify commit message after<commit id>
) orgit rebase -i --root
(modify from root commit).- change
pick
toreword
=> save and close editor:wq
=> for each chosen commit, a new text editor will open. - force push it
git push --force <remote name> <branch name>
- note: You should avoid amending a commit that is already pushed.