I had to recover a few git bare repositories from a backup, and found out that git (I am using msysgit on wondows XP) did not recognise the repo as such. After some investigation, I found the problem seems to be that the folder “refs” was missing, together with the subfolders “heads” and “remotes”. I also do not have the file “heads/master”. Is there any way I can re-create it? I really need to recover the data in these folders.
Share
Of course, if you have any checkouts of these repos, the easiest thing to do is to just recover from those.
refsjust contains files with the SHA1 of commits that those names point to;refs/heads/masteris probably all you need, containing just the SHA1 of the commit for HEAD. You didn’t lose any data (that’s all inobjects), but it might be a bit tricky to find out the SHA1 of the commits you want.If you have the file
logs/HEAD, the ref should be in there at the bottom (the first SHA1 being the parent of the most recent commit and the second being the id of it; there might be more if it’s a merge commit, not sure). For example, here’s the last line of one of my repos:so the hash starting with
feb84419b6is the one I’d want. Unfortunately, I think these are only in non-bare checkouts.If you don’t have those logs, the commits are all in the
objectsdirectory. It’s somewhat likely to be a recently modified one, which you can get on Unix for example byls -1t */* | head -10from theobjectsdirectory; you can try a couple and see what happens. If you get from this, saythen remove the
/to get the hash you want to use: