# Broken index file - any hope?

6 messages from 2008-10-03 to 2008-10-04. Participants: Jonas Schneider, Shawn O. Pearce, Jeff Whiteside, Linus Torvalds.
Thread: https://gitlist.dev/t/15778

## Jonas Schneider, 2008-10-03 21:51

Subject: Broken index file - any hope?
Message-ID: <48E693E9.708@gmx.de>
URL: https://gitlist.dev/e/48E693E9.708%40gmx.de

```
Hey guys,

I come from the Ruby on Rails world, where Git is now spreading like ... 
duh, something fast.
Today I sadly lost my complete .git directory, only the working copy was 
left behind.
I reconstructed the directory, but the index file seems to be corrupt, 
every command just tells me about a bad signature.
I hope the rest of the repository is intanct. If it is, is there any 
chance to restore/rebuild that index file from the rest?
I don't have an idea of the internals of git, but I know the objects are 
stored in different files, and maybe on top of that
I could rebuild the index file.

Any hope?
Thanks,
--Jonas Schneider

```

## Shawn O. Pearce, 2008-10-03 21:53

Subject: Re: Broken index file - any hope?
Message-ID: <20081003215319.GX21310@spearce.org>
URL: https://gitlist.dev/e/20081003215319.GX21310%40spearce.org
In-Reply-To: <48E693E9.708@gmx.de>

```
Jonas Schneider <JonasSchneider@gmx.de> wrote:
> I come from the Ruby on Rails world, where Git is now spreading like ...  
> duh, something fast.
> Today I sadly lost my complete .git directory, only the working copy was  
> left behind.
> I reconstructed the directory, but the index file seems to be corrupt,  
> every command just tells me about a bad signature.
> I hope the rest of the repository is intanct. If it is, is there any  
> chance to restore/rebuild that index file from the rest?
> I don't have an idea of the internals of git, but I know the objects are  
> stored in different files, and maybe on top of that
> I could rebuild the index file.

Give this a shot:

  git read-tree --reset HEAD
  git status

at worst you lose staged changes.  At best you recover the index
file.

-- 
Shawn.

```

## Jonas Schneider, 2008-10-03 22:03

Subject: Re: Broken index file - any hope?
Message-ID: <48E696CB.6040405@gmx.de>
URL: https://gitlist.dev/e/48E696CB.6040405%40gmx.de
In-Reply-To: <20081003215319.GX21310@spearce.org>

```
Shawn O. Pearce schrieb:
>   git read-tree --reset HEAD
Sadly, this doesnt help. I still get the same error.
But, if I remove the corrupt index file, I get this:

fatal: just how do you expect me to merge 0 trees?

Does not look like a good sign :/
Are all my branches (branch==tree?) gone? (okay, werent that much)

Thanks anyway :)
-- Jonas

```

## Shawn O. Pearce, 2008-10-03 22:07

Subject: Re: Broken index file - any hope?
Message-ID: <20081003220750.GY21310@spearce.org>
URL: https://gitlist.dev/e/20081003220750.GY21310%40spearce.org
In-Reply-To: <48E696CB.6040405@gmx.de>

```
Jonas Schneider <JonasSchneider@gmx.de> wrote:
> Shawn O. Pearce schrieb:
>>   git read-tree --reset HEAD
> Sadly, this doesnt help. I still get the same error.
> But, if I remove the corrupt index file, I get this:
>
> fatal: just how do you expect me to merge 0 trees?

Yea, so that sounds like "git log" doesn't work because HEAD isn't
pointing at a valid branch.

> Does not look like a good sign :/
> Are all my branches (branch==tree?) gone? (okay, werent that much)

Yes, a branch contains a series of trees.  The current tree of a
branch is the tree of the most recent commit on that branch.

They may be gone.

-- 
Shawn.

```

## Jeff Whiteside, 2008-10-03 22:09

Subject: Re: Broken index file - any hope?
Message-ID: <3ab397d0810031509i3e54252cp260a78de1d3faf8a@mail.gmail.com>
URL: https://gitlist.dev/e/3ab397d0810031509i3e54252cp260a78de1d3faf8a%40mail.gmail.com
In-Reply-To: <48E696CB.6040405@gmx.de>

```
I don't know if you're new to git, but I used git for about a year
before I knew what the index really was.

Remember, the index file only stores changes you made to the
checkedout code AFTER the last commit, so all your commits are safely
in the tree objects still.

The index is only a place to store changes you made with "git add",
not "git commit".

I'm not sure how you refresh the index file but i would back
everything up and try a "git reset --hard" or something.



On Fri, Oct 3, 2008 at 3:03 PM, Jonas Schneider <JonasSchneider@gmx.de> wrote:
> Shawn O. Pearce schrieb:
>>
>>  git read-tree --reset HEAD
>
> Sadly, this doesnt help. I still get the same error.
> But, if I remove the corrupt index file, I get this:
>
> fatal: just how do you expect me to merge 0 trees?
>
> Does not look like a good sign :/
> Are all my branches (branch==tree?) gone? (okay, werent that much)
>
> Thanks anyway :)
> -- Jonas
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

```

## Linus Torvalds, 2008-10-04 03:08

Subject: Re: Broken index file - any hope?
Message-ID: <alpine.LFD.2.00.0810032002240.3208@nehalem.linux-foundation.org>
URL: https://gitlist.dev/e/alpine.LFD.2.00.0810032002240.3208%40nehalem.linux-foundation.org
In-Reply-To: <48E696CB.6040405@gmx.de>

```


On Sat, 4 Oct 2008, Jonas Schneider wrote:

> Shawn O. Pearce schrieb:
> >   git read-tree --reset HEAD
> Sadly, this doesnt help. I still get the same error.
> But, if I remove the corrupt index file, I get this:
> 
> fatal: just how do you expect me to merge 0 trees?

Sounds like you didn't recreate the whole .git directory - not only was 
your index file corrupt, but apparently your .git/HEAD file is too.

The index is just a cache (apart from when you stage things into it 
and/or do merges), and the git read-tree should have recreated it for you. 
The fact that it doesn't work implies that HEAD is corrupt or missing too.

Does "git branch" work for you? And what does .git/HEAD contain (normally 
it would just contain a single line saying "ref: refs/heads/master", but 
it obviously depends on which branch you were on, and it could just be a 
detached head that just points directly to a SHA1).

		Linus

```
