I was working on a branch which was in the following state
A'--B'--C'--D'
/
A--B--C--D
some very bad things happened and I have to go back to B’ both locally and remote
so that the remote repository is the following
A'--B'
/
A--B--C--D
For the local repository I did
git reset --hard <sha>
but how can I do that for the remote repository?
I should be able to do something like
git push origin mybranch –reset
but it’s not in the man page
I tried creating a commit which would cancel the previous ones but
git add .
reports that there are no changes (expected since I’m exactly after the previous push)
So how can I reset the remote repository?
Removing Commit from History
All you really need to do is be on the B’ branch, and then go
git push --forceto overwrite the current commit pointer for that branch. If you don’t have your remotes set up as tracking branches, you may need to dogit push --force origin <branchname>instead.C’ and D’ will remain in the reflog and as objects in the repository until they are eventually pruned, but shouldn’t show up as part of any log history unless you start digging into the plumbing.
Removing Dangling Objects from the Repository
If you want C’ and D’ out of the repository altogether, you can call
git prune --expire nowin both repositories. That should remove the dangling objects altogether.