1

I was not the creator of the branch in question, but I did pull down the branch and make changes and subsequently push back up the branch. Our branch has been deleted from remote and we don't appear to have the local branches available anymore. I was hoping we would be able to recover the branch using reflog but when I run the command:

git reflog

The branch is not showing in the reflog history

The following command

git fsck --full --no-reflogs --unreachable --lost-found

Gives me a very large list of unreachable/dangling entries with the type tree, commit and blob. I can view the hashes that are of type commit by running the command git checkout <commit-hash>

What are the types tree and blob?

Is there another command that I've not come across that can be used to restore a branch that was once a local and remote branch?

Many thanks,

torek
  • 448,244
  • 59
  • 642
  • 775
Emma Middlebrook
  • 836
  • 1
  • 9
  • 19
  • How long ago did you "push back up the branch", and how long ago was "Our branch had been deleted from remote"? Also, did you ever make a PR on that branch? – TTT Aug 19 '21 at 16:33
  • "we don't appear to have the local branches available anymore" How do you know? Please show actual Git commands and responses, not generalities. – matt Aug 20 '21 at 01:50
  • 1
    The `tree` and `blob` entities are how Git stores files within the `commit` entities. The `tree` parts give name components and modes (+x/-x) while the `blob` parts hold the raw data. – torek Aug 20 '21 at 05:33
  • If you have not run `git remote prune`, maybe you still have the remote-tracking branch? Does `git branch -r | grep ...` help? – knittl Aug 20 '21 at 06:48
  • thanks for the comments. The branch was pushed over a year ago but I don't know when it got deleted. – Emma Middlebrook Aug 20 '21 at 09:19
  • With regards to the local branches. I checked what branches I had by running `git branch -a` to list my local branches and those on remote. I then ran the command `git reflog` to see what history it had a long list that contained pull forwards and some details with branch names but none matching the branch in question: 027e649ce HEAD@{101}: pull: Fast-forward 27c4daf9e HEAD@{102}: pull: Fast-forward 962884e92 HEAD@{103}: pull: Fast-forward 679cb1bfd HEAD@{104}: pull: Fast-forward a5c0eef98 HEAD@{105}: pull: Fast-forward – Emma Middlebrook Aug 20 '21 at 09:25

2 Answers2

2

I've managed to restore my branch with the help of GitHub support. They located my branch by reviewing the push logs for the repository and they located the SHA from the branch before it was deleted. Using that SHA I was able to navigate to the branch in my browser and recreate the branch. I asked if there was anything I could have done to find the branch and they said that as my branch was deleted from remote, the deletion would not have been reflected in any of my local logs.

Contacting GitHub support was the only way to recover the deleted branch. Hope this helps anyone else in this situation going forward.

Emma Middlebrook
  • 836
  • 1
  • 9
  • 19
1

GitHub does offer a poor man reflog on its side, using its GitHub Event API to list push events.

That would give an idea of when your (now deleted branch) was pushed.

Assuming this was not too long ago (not yet purged on GitHub side), you would then be able to fetch that specific commit, create a branch and push it back.

The branch was pushed over a year ago but I don't know when it got deleted.

Then it is likely to have been purged, both remotely (push events on GitHUb) and locally (reflog)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I'm not sure the API would work for me in this instance as it will only store the last 90 days. I've never used it before so not been able to get it to return anything in the last 90 days. – Emma Middlebrook Aug 20 '21 at 09:32
  • @EmmaMiddlebrook OK. It was worth a shot (since I didn't know from your question if this was recent or not) – VonC Aug 20 '21 at 09:37
  • @VonC: Do you happen to know how long Github keeps those references? – janv8000 Sep 16 '21 at 08:45
  • @janv8000 I do not: that would be a good question for GitHub support. – VonC Sep 16 '21 at 08:52