5

I pushed a commit to the remote repository and I want to undo that commit.

To undo the commit in my local repository I used
git reset --hard prev_commit_hash
(By the way, is this the proper way to do that?)

Then I tried to push, and failed, because the tip of my current branch is behind its remote counterpart, as I expected.

The question is: What is the proper way to perform a hard/forced push?

Edit:
I viewed some of the other similar questions asked, but they were a little old. The suggested solution was using git revert. And I saw that recently users commented that this solution is not working for them.

AmericanUmlaut
  • 2,817
  • 2
  • 17
  • 27
Hike Nalbandyan
  • 994
  • 1
  • 11
  • 28
  • 5
    Possible duplicate of [Git - Undo pushed commits](http://stackoverflow.com/questions/22682870/git-undo-pushed-commits) – fedorqui Sep 08 '16 at 10:55
  • I'm not sure, it was published 2 years ago... – Hike Nalbandyan Sep 08 '16 at 10:58
  • I'm not happy with the light finger down votes. I came across a problem and I'm asking a question here because it's a good community and I'm sure I'll find what I'm looking for. Besides, it's a good question and I'm sure many other users will find it very helpful. Thank you. – Hike Nalbandyan Sep 08 '16 at 11:13
  • Downvotes may be annoying, but if you keep showing effort in your questions, the number of upvotes will surpass the downvotes. Note a question being old does not mean it is good or bad. I for example posted few months ago an answer to that question. The goal of closing as duplicate is to keep the knowledge together, instead of having it spread out in different threads. – fedorqui Sep 08 '16 at 11:16
  • Yeah you're right. Thank you for your comments – Hike Nalbandyan Sep 08 '16 at 11:23

1 Answers1

10

Try using:

git push origin master -f

where f stands for forced.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Glen Pinheiro
  • 216
  • 2
  • 12