You could start with:
git reflog | grep 'to branchname'
This will match a reflog line like the following:
219daf7 HEAD@{20}: checkout: moving from master to branchname
You can use git checkout 219daf7
to have a look around and make sure it's the right commit, or I recommend tig for browsing your repository and you can use tig 219daf7
to see the history from that commit. (Bear in mind that git checkout
will add entries to your reflog, whereas tig
won't.)
Once you're satisfied you've found the right commit, you can use the following to create the branch again:
git checkout -b branchname 219daf7
Failing that, you can use the fsck approach:
git fsck --full --no-reflogs --unreachable --lost-found | grep commit
This will list any deleted commits:
unreachable commit 219daf70a24e635cd95c1493c341585bbf64a61d
You can then use the commit ID in the same way as above.