threads / discuss / 27671

corrupted Git repository

Subject: corrupted Git repository

## tl;dr

11 messages between Jun 21, 2011 and Jun 21, 2011.

replies: 10people: 5as markdown or json

Kasra Khosoussi· Jun 21, 2011, 06:58 UTC · lore
Hi all,

My thesis repository is corrupted and I don't have any recent backup (my files are OK, but the history is lost). I've seen the recovery examples in the manual, but I believe my case is somehow different. The repository is linear.

1- At the beginning, git status/log/fsck -full said:
> fatal: object 0a83757505387aacc2fd36b3c996729e6bf9d6e5 is corrupted
and there was an empty file in .git/objects/01/8375... .
2- If I move the corrupted object, git fsck --ful would return this:
> error: HEAD: invalid sha1 pointer 0a83757505387aacc2fd36b3c996729e6bf9d6e5
> error: refs/heads/master does not point to a valid object!
> dangling tree 06f388dc60cfb014b5e1f70ecdaa568efe6bd0fa
> dangling tree d86f8c75e836e13b6e0336361641223f48fde722

3- I guess I have to edit refs/heads/master and replace the corrupted sha1 with another hash, but I'm not sure how I can find the proper commit (e.g.,maybe by using find -mtime?).

Thanks in advance,
-Kasra
Michael J Gruber· Jun 21, 2011, 08:19 UTC · re: Kasra Khosoussi · lore

Re: corrupted Git repository

Kasra Khosoussi venit, vidit, dixit 21.06.2011 08:58:
> Hi all,
> 
> My thesis repository is corrupted and I don't have any recent backup
> (my files are OK, but the history is lost). I've seen the recovery

Backup now! I guess you've done that meanwhile anyways, but it's important before any recovery attempts.

Is your reflog OK, i.e. do you get proper output from "git reflog" or "git log -g"?

Show 6 quoted lines
> examples in the manual, but I believe my case is somehow different.
> The repository is linear.
> 
> 1- At the beginning, git status/log/fsck -full said:
> 
>> fatal: object 0a83757505387aacc2fd36b3c996729e6bf9d6e5 is corrupted

Hopefully and probably only the most recent commit (the one above) is lost, not all of our history.

> 
> and there was an empty file in .git/objects/01/8375... .
.git/objects/0a83... probably
Show 15 quoted lines
> 
> 2- If I move the corrupted object, git fsck --ful would return this:
> 
>> error: HEAD: invalid sha1 pointer 0a83757505387aacc2fd36b3c996729e6bf9d6e5
>> error: refs/heads/master does not point to a valid object!
>> dangling tree 06f388dc60cfb014b5e1f70ecdaa568efe6bd0fa
>> dangling tree d86f8c75e836e13b6e0336361641223f48fde722
> 
> 3- I guess I have to edit refs/heads/master and replace the corrupted
> sha1 with another hash, but I'm not sure how I can find the proper
> commit (e.g.,maybe by using find -mtime?).
> 
> Thanks in advance,
> 
> -Kasra

The reflog will give you the previous value of HEAD. You can set refs/heads/master to that (git update-ref) and then rebuild the lost commit on top of that (assuming only one commit is lost). The dangling trees are not necessarily due to the corrupt commit object. Have you changed any files since the corrupt commit? Do you remember which files you changed in that commit?

Michael
Kasra Khosoussi· Jun 21, 2011, 09:30 UTC · re: Michael J Gruber · lore

Re: corrupted Git repository

> Backup now!
> I guess you've done that meanwhile anyways, but it's important before
> any recovery attempts.
Yes, I've done that.
> Is your reflog OK, i.e. do you get proper output from "git reflog" or
> "git log -g"?

No. Before moving the corrupted object git reflog would return: fatal: object 0a83757505387aacc2fd36b3c996729e6bf9d6e5 is corrupted

and after moving the file it would say: fatal: bad object HEAD

> .git/objects/0a83... probably
Yes, it was a typo.
Show 5 quoted lines
> The reflog will give you the previous value of HEAD. You can set
> refs/heads/master to that (git update-ref) and then rebuild the lost
> commit on top of that (assuming only one commit is lost). The dangling
> trees are not necessarily due to the corrupt commit object. Have you
> changed any files since the corrupt commit?

Yes, I've changed two files after the last commit (I knew about the corruption when I was just about to commit the changes).

> Do you remember which files
> you changed in that commit?
>
> Michael
If the the corrupt commit is the last one, yes.
Thanks.
-- Kasra
Michael J Gruber· Jun 21, 2011, 09:38 UTC · re: Kasra Khosoussi · lore

Re: corrupted Git repository

Kasra Khosoussi venit, vidit, dixit 21.06.2011 11:30:
Show 14 quoted lines
>> Backup now!
>> I guess you've done that meanwhile anyways, but it's important before
>> any recovery attempts.
> 
> Yes, I've done that.
> 
>> Is your reflog OK, i.e. do you get proper output from "git reflog" or
>> "git log -g"?
> 
> No. Before moving the corrupted object git reflog would return:
> fatal: object 0a83757505387aacc2fd36b3c996729e6bf9d6e5 is corrupted
> 
> and after moving the file it would say:
> fatal: bad object HEAD

Oh yes, stupid me, sorry. "git reflog" tries to parse HEAD. But you can look at the file directly:

tail .git/logs/HEAD tail .git/logs/refs/heads/master

etc. show you what's been going on with those refs lately.

You should be able to pick the the sha1 before the corrupt one from that and do things like "git log that_sha1" if only the most recent commit is corrupt.

Michael
Kasra Khosoussi· Jun 21, 2011, 10:10 UTC · re: Michael J Gruber · lore

Re: corrupted Git repository

Thanks for your help.

I used update-ref and changed refs/heads/master to the sha1 of previous commit. Then I commit the changes. Everything seems fine now except (as you previously mentioned), git fsck -full complains about dangling trees. Is it critical?

-Kasra

On Tue, Jun 21, 2011 at 2:08 PM, Michael J Gruber <git@drmicha.warpmail.net> wrote:

Show 30 quoted lines
> Kasra Khosoussi venit, vidit, dixit 21.06.2011 11:30:
>>> Backup now!
>>> I guess you've done that meanwhile anyways, but it's important before
>>> any recovery attempts.
>>
>> Yes, I've done that.
>>
>>> Is your reflog OK, i.e. do you get proper output from "git reflog" or
>>> "git log -g"?
>>
>> No. Before moving the corrupted object git reflog would return:
>> fatal: object 0a83757505387aacc2fd36b3c996729e6bf9d6e5 is corrupted
>>
>> and after moving the file it would say:
>> fatal: bad object HEAD
>
> Oh yes, stupid me, sorry. "git reflog" tries to parse HEAD. But you can
> look at the file directly:
>
> tail .git/logs/HEAD
> tail .git/logs/refs/heads/master
>
> etc. show you what's been going on with those refs lately.
>
> You should be able to pick the the sha1 before the corrupt one from that
> and do things like "git log that_sha1" if only the most recent commit is
> corrupt.
>
> Michael
>
Ilari Liusvaara· Jun 21, 2011, 10:39 UTC · re: Kasra Khosoussi · lore

Re: corrupted Git repository

On Tue, Jun 21, 2011 at 02:40:47PM +0430, Kasra Khosoussi wrote:
Show 6 quoted lines
> Thanks for your help.
> 
> I used update-ref and changed refs/heads/master to the sha1 of
> previous commit. Then I commit the changes. Everything seems fine now
> except (as you previously mentioned), git fsck -full complains about
> dangling trees. Is it critical?
 
Dangling trees are normal. They are not errors.
-Ilari
Kasra Khosoussi· Jun 21, 2011, 10:40 UTC · re: Ilari Liusvaara · lore

Re: corrupted Git repository

Thanks for your help.

On Tue, Jun 21, 2011 at 3:09 PM, Ilari Liusvaara <ilari.liusvaara@elisanet.fi> wrote:

Show 12 quoted lines
> On Tue, Jun 21, 2011 at 02:40:47PM +0430, Kasra Khosoussi wrote:
>> Thanks for your help.
>>
>> I used update-ref and changed refs/heads/master to the sha1 of
>> previous commit. Then I commit the changes. Everything seems fine now
>> except (as you previously mentioned), git fsck -full complains about
>> dangling trees. Is it critical?
>
> Dangling trees are normal. They are not errors.
>
> -Ilari
>
Johannes Sixt· Jun 21, 2011, 13:47 UTC · re: Kasra Khosoussi · lore

Re: corrupted Git repository

Am 6/21/2011 12:10, schrieb Kasra Khosoussi:
> Everything seems fine now

But it would still be good to know how the corruption could have happened. Do you have any clues?

Disk full? Ctrl-C in the middle of a git operation? Some cron script interference (unlikely)? Permission problems (unlikely)? Networking problems (only if the repository is on a network mount)? Something else?

-- Hannes
Kasra Khosoussi· Jun 21, 2011, 14:26 UTC · re: Johannes Sixt · lore

Re: corrupted Git repository

Good question! Actually I have no idea!

It was fine yesterday. I had to leave home so I just shutdown my netbook (I just issued the command and closed the lid). Files were open in my editor but I'm sure that there were no Git processes running at the time. The battery was empty this morning, so my best guess is that the halt operation was somehow failed, but I think it can not explain the corruption.

Any idea?
-Kasra
On Tue, Jun 21, 2011 at 6:17 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:
Show 15 quoted lines
> Am 6/21/2011 12:10, schrieb Kasra Khosoussi:
>> Everything seems fine now
>
> But it would still be good to know how the corruption could have happened.
> Do you have any clues?
>
> Disk full?
> Ctrl-C in the middle of a git operation?
> Some cron script interference (unlikely)?
> Permission problems (unlikely)?
> Networking problems (only if the repository is on a network mount)?
> Something else?
>
> -- Hannes
>
Carlos Martín Nieto· Jun 21, 2011, 14:32 UTC · re: Kasra Khosoussi · lore

Re: corrupted Git repository

On Tue, Jun 21, 2011 at 06:56:55PM +0430, Kasra Khosoussi wrote:
Show 10 quoted lines
> Good question! Actually I have no idea!
> 
> It was fine yesterday. I had to leave home so I just shutdown my
> netbook (I just issued the command and closed the lid). Files were
> open in my editor but I'm sure that there were no Git processes
> running at the time. The battery was empty this morning, so my best
> guess is that the halt operation was somehow failed, but I think it
> can not explain the corruption.
> 
> Any idea?

Does your computer actually shutdown or suspend? It could be that the files still hadn't been flushed to disc when the battery ran out, but that is unlikely if it did keep running.

Cheers,
   cmn
Kasra Khosoussi· Jun 21, 2011, 14:59 UTC · re: Carlos Martín Nieto · lore

Re: corrupted Git repository

The battery was not empty when I issued the shutdown command, so there should have been plenty of time before it ran out.

-Kasra
On Tue, Jun 21, 2011 at 7:02 PM, Carlos Martín Nieto <cmn@elego.de> wrote:
Show 19 quoted lines
> On Tue, Jun 21, 2011 at 06:56:55PM +0430, Kasra Khosoussi wrote:
>> Good question! Actually I have no idea!
>>
>> It was fine yesterday. I had to leave home so I just shutdown my
>> netbook (I just issued the command and closed the lid). Files were
>> open in my editor but I'm sure that there were no Git processes
>> running at the time. The battery was empty this morning, so my best
>> guess is that the halt operation was somehow failed, but I think it
>> can not explain the corruption.
>>
>> Any idea?
>
> Does your computer actually shutdown or suspend? It could be that the
> files still hadn't been flushed to disc when the battery ran out, but
> that is unlikely if it did keep running.
>
> Cheers,
>   cmn
>

← back to recent threads