5

I've made some changes in my master branch that I no longer see fit. For arguments sake, I have a commit hash named 791fda4e1ac0e1a393e01340bf0fba3f333a73ff that I'd like to make my HEAD now, as that's when everything was stable in the repo. I've tried to do the following:

git reset 791fda4e1ac 
git reset --soft HEAD@{1} 
git commit -m "Revert to 791fda4e1ac"
git reset --hard 

Yet, when I do a git push origin, I get rejected, because origin thinks it's a non-fastforward push:

 ! [rejected]        master -> master (non-fast-forward)

What's the right way of reverting my HEAD back to commit hash 791fda4e1ac and getting the origin server there as well?

SensorSmith
  • 1,129
  • 1
  • 12
  • 25
randombits
  • 47,058
  • 76
  • 251
  • 433

2 Answers2

10

It's rejected because it is non-fast-forward — it discards history others may have built on.

Use git revert instead to create a new commit which undoes the effect of the existing ones.

Or, if you're sure no one else is using your repository and you don't care about those commits in the future, go ahead and git push -f to ignore the warning.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
  • 1
    @drevicko See http://stackoverflow.com/questions/1463340/revert-multiple-git-commits for various possibilities. I like http://stackoverflow.com/questions/1463340/revert-multiple-git-commits#comment19940208_11743042 best. – CletusW Jun 16 '16 at 18:48
2

You have to do a forced push (git push -f origin).

dty
  • 18,795
  • 6
  • 56
  • 82