threads / discuss / 15778

Broken index file - any hope?

Subject: Broken index file - any hope?

## tl;dr

6 messages between Oct 3, 2008 and Oct 4, 2008.

replies: 5people: 4as markdown or json

Jonas Schneider· Oct 3, 2008, 21:51 UTC · lore
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· Oct 3, 2008, 21:53 UTC · re: Jonas Schneider · lore

Re: Broken index file - any hope?

Jonas Schneider <JonasSchneider@gmx.de> wrote:
Show 11 quoted lines
> 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· Oct 3, 2008, 22:03 UTC · re: Shawn O. Pearce · lore

Re: Broken index file - any hope?

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· Oct 3, 2008, 22:07 UTC · re: Jonas Schneider · lore

Re: Broken index file - any hope?

Jonas Schneider <JonasSchneider@gmx.de> wrote:
Show 6 quoted lines
> 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· Oct 3, 2008, 22:09 UTC · re: Jonas Schneider · lore

Re: Broken index file - any hope?

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:
Show 19 quoted lines
> 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· Oct 4, 2008, 03:08 UTC · re: Jonas Schneider · lore

Re: Broken index file - any hope?

On Sat, 4 Oct 2008, Jonas Schneider wrote:
Show 6 quoted lines
> 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

← back to recent threads