bLAZ
bLAZ

Reputation: 1751

Remove remote commit in git

I can't find working solution for my problem:

How to remove commit in local and also in remote repository. Here is one solution. But when I try this I can go back with reset command in my local repository. But I can't push it. The error message says: remote: error: denying non-fast-forward refs/heads/master (you should pull first) But after pull my master points again to the commit that I want to remove.

Can you help?

EDIT - my try:

$ git reset --hard HEAD^1
HEAD is now at 1c50f9c good commit

$ git push -f
Total 0 (delta 0), reused 0 (delta 0)
remote: error: denying non-fast-forward refs/heads/master (you should pull first)
To E:/reps/gf.git
 ! [remote rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'E:/reps/gf.git'

Upvotes: 3

Views: 2031

Answers (1)

user4815162342
user4815162342

Reputation: 155610

Your remote repository likely has a setup that disallows non-fast-forward pushes on the server side. You have two options:

  1. Contact the server administrators, explain your case, and ask them to (temporarily) rescind the no-fast-forward-push policy, with something like git config receive.denyNonFastForwards. (You will still need the -f flag to push.)

  2. Use git revert instead of git reset, and push the resulting commit. Both the commit and its inverse will be visible, but sometimes that cannot be avoided. Unless the original commit contains sensitive data, this should be a big deal—git commits get reverted all the time. If the original commit does contain sensitive data, see option 1.

Upvotes: 4

Related Questions