Amend Git Message

Modify git commit message

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