Our remote master branch was deleted. I have a local copy of the master repo but it is a few revs out of date. I'm able to see the branch in github by plugging the last known commit hash into the URL, but have been unsuccessful at restoring it. I've tried several steps to recover it:
git reset --hard 16deddc05cb53dfaa2d198b1cf264416e19255e9
fatal: Could not parse object '16deddc05cb53dfaa2d198b1cf264416e19255e9'
git checkout 16deddc05cb53dfaa2d198b1cf264416e19255e9
fatal: reference is not a tree: 16deddc05cb53dfaa2d198b1cf264416e19255e9
Understandable since master no longer exists. What are my options to recover here?
Fetch the exact commit (and everything down its line of history):
git fetch origin 16deddc05cb53dfaa2d198b1cf264416e19255e9
Create a branch out of it:
git branch xyzzy FETCH_HEAD
You can combine this into a single step:
git fetch 16deddc05cb53dfaa2d198b1cf264416e19255e9:refs/heads/xyzzy
If you don't know the hash for the latest rev, you might be out of luck for recovering it. Perhaps the best you can do is simply push the master branch that you have back up to github. Since the revisions are already in the repository, it will be a quick network operation.
If you have ssh access to the machine hosting your repository (which you do not, on github) then you can do a search for orphans in the git repository. An orphan is a commit that no longer has references. Unfortunately, that won't help you in this case.
There are some pointers that can help you recover lost commits, including the process for finding orphans in this post:
Git: Recover deleted (remote) branch
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