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…
A deleted Git branch can be restored at any time, regardless of when it was deleted. Open your repo on the web and select the Branches view. Search for the exact branch name using the Search all branches box in the upper right. Click the link to Search for exact match in deleted branches.
Yes, you should be able to do git reflog --no-abbrev and find the SHA1 for the commit at the tip of your deleted branch, then just git checkout [sha] . And once you're at that commit, you can just git checkout -b [branchname] to recreate the branch from there.
Yes, it's possible to restore a deleted branch from git.
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.
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