threads / discuss / 60695

Analyzing a corrupted index file

Subject: Analyzing a corrupted index file

## tl;dr

4 messages between Jan 7, 2024 and Jan 9, 2024.

replies: 3people: 2as markdown or json

Nathan Manceaux-Panot· Jan 7, 2024, 15:22 UTC · lore
Hello all,

I have a corrupted git index file, and am trying to read it by hand, to understand what's wrong with it. Are there any tools that'll let me parse the on-disk, binary version of the index file, to unpack it into a human-readable data structure? I found the spec for the index binary format, but reading it in that way is beyond my abilities.

For context, I'm writing a git tool, and my code is causing the index file to be screwed up in some unknown way. When it's in that state, git (v2.43) becomes inconsistent with itself:
- In the workdir, the file contains A
- According to `git show :file`, the file in the index contains B
- But `git diff` reports no changes!
The inconsistency goes away with a simple `git reset`, but can then be easily reproduced by re-executing my tool.

Thank you, Nathan

Junio C Hamano· Jan 8, 2024, 19:51 UTC · re: Nathan Manceaux-Panot · lore

Re: Analyzing a corrupted index file

Nathan Manceaux-Panot <fresh.tree3651@lemon.garden> writes:
> I have a corrupted git index file, and am trying to read it by
> hand, to understand what's wrong with it. Are there any tools
> that'll let me parse the on-disk, binary version of the index
> file, to unpack it into a human-readable data structure?

"git ls-files" with its various options is probably the closest, but even the command is not meant for "debugging the bits". It is more about showing lower-level details of a working index file to help diagnose the mismatch between end-user expectation and the reality (e.g. the user says the conflicts were all resolved, an expert asks to run "ls-files -u" and together they discover that there are paths that are still unmerged).

Nathan Manceaux-Panot· Jan 9, 2024, 14:42 UTC · re: Junio C Hamano · lore

Re: Analyzing a corrupted index file

> On Jan 8, 2024, at 20:51, Junio C Hamano <gitster@pobox.com> wrote:
> 
> "git ls-files" with its various options is probably the closest, but
> even the command is not meant for "debugging the bits"
Thanks for the pointer. In the meantime I've started to make sense of the binary representation, against all odds, so there's hope for me there!
Junio C Hamano· Jan 9, 2024, 17:16 UTC · re: Nathan Manceaux-Panot · lore

Re: Analyzing a corrupted index file

Nathan Manceaux-Panot <fresh.tree3651@lemon.garden> writes:
Show 8 quoted lines
>> On Jan 8, 2024, at 20:51, Junio C Hamano <gitster@pobox.com> wrote:
>> 
>> "git ls-files" with its various options is probably the closest, but
>> even the command is not meant for "debugging the bits"
>
> Thanks for the pointer. In the meantime I've started to make sense
> of the binary representation, against all odds, so there's hope
> for me there!

Documentation/gitformat-index.txt may be a good place to start, of course.

https://github.com/git/htmldocs/blob/gh-pages/gitformat-index.txt

← back to recent threads