KM.
KM.

Reputation: 1389

Reverting a remote git repo after a reset done locally

How does one revert a remote git repo after a reset done locally?

We had accidentally pushed changes to master branch. I've reverted the code in the local branch to the last good commit. Now, I am trying to update the remote repo so that it is also at the last commit -- future pulls and clones are at the last good commit, but and running into errors.

Here is what I've tried:

git reset --hard <last-good-commit-hash>

which worked fine

Then, to update the remote repo,

git push origin master

Which gave me:

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'host:/srv/git/cms'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

Then, I tried:

git push --force origin master

Total 0 (delta 0), reused 0 (delta 0)
remote: error: denying non-fast-forward refs/heads/master (you should pull first)
To host:/srv/git/cms
 ! [remote rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'host:/srv/git/cms'

If I do a pull, I am back to the bad commits.

Upvotes: 0

Views: 239

Answers (2)

J-16 SDiZ
J-16 SDiZ

Reputation: 26930

Check your config file on server, does it have denyNonFastForwards=true?

If yes, do this:

git config receive.denyNonFastForwards false

Upvotes: 2

Peter van der Does
Peter van der Does

Reputation: 14508

Instead of git reset <commit> try

git revert <commit>
git push origin master

Upvotes: 2

Related Questions