Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I open my Git repository using gitExtensions on Windows 7 for a Visual Studio project. It is suddenly empty. The repository exists, but all my commits have disappeared.

I am using the graphical interface and I believe this is the first time I've opened it since they updated it.

I'm unsure what to do about getting back my commits.

When I type

git log 

I receive

fatal:bad default revision 'HEAD'

Update
After looking at http://stackoverflow.com/questions/1545407/recovering-broken-git-repository i tried

git fsck

it returned:

error: Invalid HEAD
fatal: loose object 36b7d9e1ca496bcb864c0b9c8671fcec97fbda31 (stored in .git/obj ects/36/b7d9e1ca496bcb864c0b9c8671fcec97fbda31) is corrupt

Committing returns:

error: unable to resolve reference HEAD: No such file or directory
fatal: cannot lock HEAD ref

and logging master branch returns

$ git log master warning: ignoring broken ref refs/heads/master. warning: ignoring broken ref refs/heads/master. fatal: ambiguous argument 'master': unknown revision or path not in the working tree. Use '--' to separate paths from revisions

Ill just keep pasting things that could be relevant

$ git reflog master
warning: ignoring broken ref refs/heads/master.
warning: ignoring broken ref refs/heads/master.
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

More possibly useful info: every single time i delete the corrupt file another one takes it's place. Im beginning to think its something to do with the master branch pointing to the wrong thing or something. because i assume the head is pointing to master.

One day later:
So I got my mate onto this, he was able to go through the logs and he said that the hashes in the logs don't match up to the objects in the folder. He tried resetting the master branch to the logs or something like that, I got a bit lost. Hope thats helpful

share|improve this question
    
1  
@heavyd please check update –  MrJD May 9 '12 at 3:42

2 Answers 2

The repository exists, but all my commits have disappeared.

What exactly do you mean? Is the working tree still there? Does .git/ exist? Are there any files in it?

The messages you posted suggest that the file .git/HEAD does not exist. It defines the expected state of the working tree (what you had checked out). If that file is gone, git doesn't know where you were.

You could try creating the file yourself, with this content: ref: refs/heads/master

If you were on a different branch, just replace "master" with the branch name. If you were not on a branch, it would be more complicated.

.git/logs/HEAD records past states of HEAD, with later lines at the bottom. This example line shows a checkout: 25f2a6099fb5f9f2192a510c42f704f9fc4bcecb 65abb1a3dc102e2498860f01fb179cda4c51decb Rainer Blome <rainer.blome@wherever.you.are.com> 1346938344 +0200 checkout: moving from master to MySuperBranch

The SHA1s in front refer to commits. You ought to be able to find these in the branch log, for example .git/logs/refs/heads/master.

The git reflog output you gave looks like refs/heads/masteris missing as well. Its sole content is supposed to be the SHA1 of the latest commit on it (and a newline). You can find the latest SHA1 at the end of the branch log, for example .git/logs/refs/heads/master.

share|improve this answer

It sounds like your repo has been corrupted. The easiest thing to do would be to recover your repo from a backup or re-clone the repo from the original source (assuming you didn't have tons of work in the repo).

If resotring/cloning is not an option I would recommend reading through Pro Git (free online book or the paper version). The whole book is very informative, but especially take a look at the last chapter to get an understanding of how Git works internally. Once you have an understanding of how Git works, take a look at Linus' instructions on recovering corrupted objects.

share|improve this answer
    
So, sadly I wasn't backing up hidden files, .git was hidden. I don't really have enough time to read an entire book, is there anything you think I could attempt? –  MrJD May 10 '12 at 4:55
    
"Read a book about the internals" might be sound general advice but it doesn't help address the specific problem and question at hand. –  Burhan Ali Aug 28 '12 at 22:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.