KexAri KexAri - 1 year ago 90
Git Question

Revert to specific commit but can't push

I want to reset to a specific commit. I use the command

git reset --hard Head~5
This has reset my local. I make some changes and now I want to push. However I get
Updates were rejected because the tip of your current branch is behind
. I don't want to pull though otherwise I'm back to the most recent commit. How do I reset?

Answer Source

You can forcibly push but this is potentially problematic.

Are there other people working on this repo or is it just you? Are you absolutely sure you want to erase those commits from the remote?

git push -f origin branch-name will update the remote branch to match the changes you've just made.

But you need to take care when doing this. If you have colleagues working on the same branch you should tell them in case they have already pulled in those changes. Plus they may have pushed other changes which you'd be overriding.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download