Skip to main content

Changing a commit message

Amend unclear, incorrect, or sensitive commit messages locally and push updated commits to GitHub, including steps for editing recent or older commits.

Rewriting the most recent commit message

Changing a commit message creates a new commit ID. If the commit has already been pushed, you must force push the rewritten history.

Commit has not been pushed online

If the commit only exists in your local repository, amend the commit message locally.

  1. On the command line, navigate to the repository that contains the commit you want to amend.

  2. Type git commit --amend and press Enter.

  3. In your text editor, edit the commit message, and save the commit.

  4. Push the commit to GitHub.com.

Amending older or multiple commit messages

If you have already pushed the commit, use caution before rewriting history. Force pushing can disrupt collaborators who have based work on the old commits.

Changing the message of the most recently pushed commit

  1. Follow the steps in Commit has not been pushed online to amend the commit message.

  2. Force push over the old commit.

    git push --force-with-lease origin EXAMPLE-BRANCH
    

Changing the message of older or multiple commit messages

Use interactive rebase to change older or multiple commit messages.

  1. On the command line, navigate to the repository that contains the commits you want to amend.

  2. Start an interactive rebase for the last n commits.

    git rebase -i HEAD~n
    
  3. In the commit list, replace pick with reword before each commit message you want to change.

    pick e499d89 Delete CNAME
    reword 0c39034 Better README
    reword f7fde4a Change the commit message
    
  4. Save and close the commit list file.

  5. In each commit message file that opens, enter the new message, then save and close the file.

  6. Force push the rewritten history.

    git push --force-with-lease origin EXAMPLE-BRANCH
    

See Interactive mode in the Git manual.

Warning

If a commit message included sensitive information, force pushing an amended commit might not remove the original commit from GitHub. Contact us through the GitHub Support portal with the old commit ID to have it purged from the remote repository.

Further reading