This question already has an answer here:
I have deleted my branch by mistake like this:
git branch -D demo
But I want to recover it… I get this after git reflog
541b2f5 HEAD@{23}: checkout: moving from demo to master 06fa6d5 HEAD@{24}: commit (merge): remove ajax call for deleting variables and transfomers b84b60a HEAD@{25}: checkout: moving from demo1 to demo
I want to create branch with sha 06fa6d5… so I tried this:
git checkout -b demo 06fa6d5 git checkout -b demo HEAD@{24}
But I didn't get code from that…
Create a list of all dangling or unreachable commits.
git fsck --full --no-reflogs --unreachable --lost-found
Print a list of commit messages for all commits in the lost and found.
ls -1 .git/lost-found/commit/ | xargs -n 1 git log -n 1 --pretty=oneline
Find your missing commit through the process of manual inspection (i.e. reading). Create a new branch with the missing commit as the branch head.
git checkout -b branch-name SHA
Having got the potential sha1 for the last tip of branch demo, use gitk sha1 to actually browse the commit's history to check you have the right one.