Reputation: 2418
I have a few commits I want to get rid off. If I use the line below they disappear but if I do a sync or pull
they return.
git reset --hard HEAD^1
How do I make sure the reset sticks on a remote branch named master
?
Upvotes: 2
Views: 76
Reputation:
Does anyone else have access to the remote repository? If so, you'll need to apologize to them first, and warn them to back up their refs before their next pull, in case they have any work done since your bad push.
Once you've reset-hard, push-force.
$ git push -f
Be warned: you're forcing a push, meaning you're throwing away commits from a remote (shared?) repository. This affects any and all other collaborators, in a term coined "pulling the rug from under people's feet".
Upvotes: 2
Reputation: 98459
You need to push the new HEAD to the remote master.
git push origin +HEAD:master
This is very dangerous. Make triply sure you're pushing the right thing. Anyone else who pulled the "bad" commits will have trouble.
Upvotes: 3
Reputation: 137398
You're not supposed to. Once pushed, your commits are published and shouldn't be removed. Otherwise you could prevent changes someone else has made atop the original commit from being merged.
Instead you should git revert
the bad commit and push the new commit that removes it.
Other answers will tell you how to "force push" but considering your question is tagged GitHub, your code should already be considerd public.
Upvotes: 3