14

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.

random
  • 9,571
  • 10
  • 67
  • 79
emilan
  • 12,345
  • 11
  • 31
  • 37

2 Answers2

22

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.

ThiefMaster
  • 298,938
  • 77
  • 579
  • 623
  • I did git commit --amend and modified the message, but after that i don't know what to do. Here is all available commands ^G Get Help ^O WriteOut ^R Read File ^Y Prev Page ^K Cut Text ^C Cur Pos ^X Exit ^J Justify ^W Where Is ^V Next Page ^U UnCut Text ^T To Spell – emilan Apr 14 '12 at 13:04
  • 2
    So you don't know how to use your default editor?! It looks like `nano`, so simply press `CTRL+X`, followed by `Y`, followed by `RETURN` – ThiefMaster Apr 14 '12 at 13:08
  • sorry it doesn't help me, because I want to change commit message after pushing. git commit --amend doesn't work in this situation. – emilan Apr 14 '12 at 13:19
  • 2
    @emilan If you want to change it, after you pushed, you will need to do as ThiefMaster says and push again with the --force option. – Andy Apr 14 '12 at 14:30
0

If you wrote the wrong thing and the commit has not yet been pushed, you can do the following to change the commit message:

$ git commit --amend

This will open your default text editor, where you can edit the message. On the other hand, you can do this all in one command:

$ git commit --amend -m 'xxxxxxx'

If you have already pushed the message, you can amend the commit and force push, but this is not recommended.

To force push : git push --force

Amitesh Bharti
  • 10,566
  • 5
  • 53
  • 51