Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit an incorrect commit message in Git that has already been pushed

I did a Git commit and push, but wrote the totally wrong thing in the comment.

How do I change the comment? I have already pushed the commit to the remote.

like image 361
emilan Avatar asked Apr 14 '12 12:04

emilan


People also ask

How do I edit an existing pushed commit message?

If the commit only exists in your local repository and has not been pushed to GitHub.com, you can amend the commit message with the git commit --amend command. On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter.

Can I edit commit message in git?

There are many ways to rewrite history with git. Use git commit --amend to change your latest log message. Use git commit --amend to make modifications to the most recent commit. Use git rebase to combine commits and modify history of a branch.

Can I edit a previous commit?

You can modify the most recent commit in the same branch by running git commit --amend. This command is convenient for adding new or updated files to the previous commit. It is also a simple way to edit or add comments to the previous commit. Use git commit --amend to modify the most recent commit.


1 Answers

git commit --amend will allow you to edit the commit message.

If you already pushed that commit, you need to run git push --force. Only do that if you are sure nobody pulled it yet!

If people pulled the commit from your repo, simply leave the message as it is.

like image 83
ThiefMaster Avatar answered Sep 29 '22 18:09

ThiefMaster