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.
-
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.
- To add a co-author, add a trailer to the commit. See Creating a commit with multiple authors or on behalf of an organization.
-
Push the commit to お使いの GitHub Enterprise Server インスタンス.
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
-
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
Changing the message of older or multiple commit messages
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.
警告
If a commit message included sensitive information, force pushing an amended commit might not remove the original commit from GitHub. Contact サイト管理者 with the old commit ID to have it purged from the remote repository.