Set remote branch to a commit we don't have locally
Some intern did a force push on master yesterday. After we’ve done scolding, 😉 we looked at the result. Luckily, we had an almost up to date version of the master on one machine, only some pull requests have to be merged again.
But one thing is bugging me: We found the old HEAD commit referenced in the last merged pull requests (on github), but since no branch or tag was pointing to it anymore, we couldn’t find any way to either pull that commit (
git pull origin <SHA1> didn’t work) or to set a remote branch to that commit. Do you see any way to do that?
2 Solutions collect form web for “Set remote branch to a commit we don't have locally”
Assuming from your comment that you use
You should ask
GitHub techsupport to check the reflog of your
GitHub project. If less than 30 days have passed your reflog will still contain the commit you are looking for. Just pass them the hash if you know it. Ask them to reset HEAD into this commit.
These links should be useful:
P.S. If they give you a hint how to do it yourself – please, post it here as the answer.
Added: This is the great link on the subject: https://help.github.com/articles/commit-exists-on-github-but-not-in-my-local-clone
If you can see the commit on GitHub, e.g. at https://github.com/%5Borg%5D/%5Brepo%5D/commit/%5Bsha%5D but it is orphaned, GitHub won’t include it when you clone/fetch the repo.
If you change the URL slightly, though, to https://github.com/%5Borg%5D/%5Brepo%5D/tree/%5Bsha%5D, you can use the branch dropdown to create a branch at that commit: