Windows – Git corrupt master branch

gitvisual studio 2010windowswindows 7

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 https://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

Best Answer

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.

Related Question