1

I was so dumb that I committed and pushed it to the server and found out that the commit message was wrong. So I used --amend to fix the comment. But now I can't push to the server anymore :S

What to do?

Martin G
  • 17,357
  • 9
  • 82
  • 98
Spoeken
  • 2,549
  • 2
  • 28
  • 40
  • 2
    possible duplicate of [How do I push amended commit to the remote git repo?](http://stackoverflow.com/questions/253055/how-do-i-push-amended-commit-to-the-remote-git-repo) – CharlesB Apr 20 '12 at 12:13

1 Answers1

2

You need to push with -f to force the push, since you are rewriting history:

git push -f origin master
rtn
  • 127,556
  • 20
  • 111
  • 121
  • And it won't mess it up at all? – Spoeken Apr 20 '12 at 11:56
  • 1
    Do you want to push or not? :) You have to use -f/--force if you are rewriting history. Using --amend when commiting is rewriting history, if you only changed the commit message then it should be completely safe. – rtn Apr 20 '12 at 12:05
  • 2
    @Mathias: yes, it is a dangerous operation. For instance, if someone/something else has pulled in the meantime, they will run into problems when the branch changes to point to something else. If you know for sure that the only repos that the bad commit is on are yours and the server, then by all means use `-f` to force... – Avi Apr 20 '12 at 12:10
  • Im the only one working on this rep, so its ok. And if someone else where working on it to I could just tell them to fetch, right? – Spoeken Apr 20 '12 at 12:14
  • 2
    Wrong!. If other users already pull the code before you force, it mean that they get trouble by cannot commit or fetch the code after you force it back to repository. This is because SHA1 hash change after you force push. but the other have reference with old SHA1 hash which not exists in the system anymore. It may be ok for your repository but it not best practice to do in general repository which have to coperate with others. – scalopus Apr 20 '12 at 14:14