Recover deleted branch in Git [duplicate]

我的梦境 提交于 2019-11-27 05:34:49

问题


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…


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/16793637/recover-deleted-branch-in-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!