Reputation: 235
I don't know how it happened, but I had a data loss and was only left with a .git
directory containing only an objects
directory.
I've followed the steps from Recovering Git repository from objects only:
git init
objects
directory I had to the new .git/objects
directorygit fsck
command.The output of the above steps produced the following msg:
notice: HEAD points to an unborn branch (master)
notice: No default references
dangling commit 0b2c7d52b6a7e6d4e2858e9ebf207c315407c87c
dangling commit 8dceafea1634c923069f6d4b925839c28d92c4e5
dangling commit dd7bdd04c557a018c15fd0948075121f181decd1
When I try to run git log
at this stage I get fatal: bad default revision 'HEAD'
.
What should I do in order to recover my data???
EDIT:
klaustopher's suggestion:
/refs/heads
called master
containing one of the dangling commits.fatal: unable to read tree 3c864da48b16ad0dc5f8ae585380270a708a1e56
Upvotes: 1
Views: 2052
Reputation: 6941
Well, you got the objects but git has no idea which is the commit it should interpret as the master. There are three suggestions in the output of git fsck
. You could try the following:
.git/refs/heads
directory and create a file called master
git checkout master
If that is not the commit you were looking for, put in another sha1 hash in the master
-file
--
Edit: If those aren't real commits like you described in the comment, than you should maybe go through your objects. With git show 2452845a7b526db3dfbf88c1c2ca05967ef9653a
you can see the contents of the file. If it is a commit it will start with the word commit
and also have the date, commit message, etc in it. You could maybe write a little shell script to go through all the objects. When you found your commit, put its sha1 in the refs/heads/master file and do what I described above
Upvotes: 1