| title | Changing a commit message | ||||||
|---|---|---|---|---|---|---|---|
| redirect_from |
|
||||||
| intro | Amend unclear, incorrect, or sensitive commit messages locally and push updated commits to {% data variables.product.github %}, including steps for editing recent or older commits. | ||||||
| versions |
|
||||||
| category |
|
||||||
| contentType | how-tos | ||||||
| shortTitle | Change a 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.
If the commit only exists in your local repository, amend the commit message locally.
- On the command line, navigate to the repository that contains the commit you want to amend.
- Type
git commit --amendand press Enter. - In your text editor, edit the commit message, and save the commit.
- Push the commit to {% data variables.location.product_location %}.
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.
-
Follow the steps in Commit has not been pushed online to amend the commit message.
-
Force push over the old commit.
git push --force-with-lease origin EXAMPLE-BRANCH
Use interactive rebase to change older or multiple commit messages.
-
On the command line, navigate to the repository that contains the commits you want to amend.
-
Start an interactive rebase for the last
ncommits.git rebase -i HEAD~n
-
In the commit list, replace
pickwithrewordbefore each commit message you want to change.pick e499d89 Delete CNAME reword 0c39034 Better README reword f7fde4a Change the commit message
-
Save and close the commit list file.
-
In each commit message file that opens, enter the new message, then save and close the file.
-
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 {% data variables.product.github %}. Contact {% data variables.contact.contact_support %} with the old commit ID to have it purged from the remote repository.