I found some solutions on how to recover git branches by using
I can't reach some commits from deleted branch or any history of deletion of this branch.
The local branch is not yet merged in my master branch and accidentally deleted. Is it possible to recover it? Thanks for your help!
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.
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