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?
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.
You have to do a forced push (git push -f origin
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With