Recover deleted branch in Git [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:08:02

问题:

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…

回答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.



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