0

4-5 months ago, I deleted one of the remote/local branches (named as "dev0001"). Now, I need to access that branch. Therefore, I need to find the latest commit hash inside that deleted branch so that I can recover it.

Do you know how to find the latest commit hash of a deleted branch and then checkout it to my local computer?

I found lots of questions and answers on Stackoverflow regarding recording a branch but don't know how to find latest commit hash of a deleted branch 4-5 months ago.

Thanks for your help!

Cem
  • 179
  • 5
  • 1
    You might want to look at http://stackoverflow.com/questions/5543280/how-do-i-get-the-deleted-branch-back-in-git or http://stackoverflow.com/questions/5543280/how-do-i-get-the-deleted-branch-back-in-git – Olaf Dietsche Oct 22 '12 at 13:57
  • Thanks Olaf, but git log doesn't list commits made on a deleted branch :( – Cem Oct 22 '12 at 14:05
  • these questions deal with deleted branch, why don't they fit to your problem? – CharlesB Oct 22 '12 at 14:08
  • Yes, they deal with the deleted branch but deleted branches which have been merged to master branch. In my case, the dev0001 branch has never been merged to master or any other existing branch :( I guess I can find a hash via git fsck. If I can find the solution, I will post it here. – Cem Oct 22 '12 at 14:28
  • Have you already searched for `git reflog | grep 'moving.*dev0001'`? – Olaf Dietsche Oct 22 '12 at 14:31
  • You might also try `git fsck`. Options `--unreachable` and `--lost-found` might be interesting, too. – Olaf Dietsche Oct 22 '12 at 14:51
  • Olaf, thanks for comments. git fsck returned me unreachable commits. I achieved to checkout a branch commit (I found the commit hash from fsck) but some files are missing, unable to retrieve them. Any comments? – Cem Oct 22 '12 at 16:02

1 Answers1

0

If you can view the reflog for that branch, it will list the commits - you can try:

git reflog show dev0001

Alternatively, you can search the reflog for HEAD:

git reflog

... for mentions of dev0001.

However, since the default time for reflog entries to expire is 90 days, that may not produce any results.

Are you sure that any remote-tracking branches for dev0001 have also been deleted? To check that, I would try:

git branch -a | grep dev0001

... in every repository that might have fetched that branch at some point. It's common for people to have remote-tracking branches left over even after they've been deleted on the server they originally fetched it from.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327