# corrupted Git repository

11 messages from 2011-06-21 to 2011-06-21. Participants: Kasra Khosoussi, Michael J Gruber, Ilari Liusvaara, Johannes Sixt, Carlos Martín Nieto.
Thread: https://gitlist.dev/t/27671

## Kasra Khosoussi, 2011-06-21 06:58

Subject: corrupted Git repository
Message-ID: <BANLkTi=A=DpyfNwEeSd6N6ibCsA5qh_NPQ@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTi%3DA%3DDpyfNwEeSd6N6ibCsA5qh_NPQ%40mail.gmail.com

```
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, 2011-06-21 08:19

Subject: Re: corrupted Git repository
Message-ID: <4E005404.5010901@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4E005404.5010901%40drmicha.warpmail.net
In-Reply-To: <BANLkTi=A=DpyfNwEeSd6N6ibCsA5qh_NPQ@mail.gmail.com>

```
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"?

> 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

> 
> 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, 2011-06-21 09:30

Subject: Re: corrupted Git repository
Message-ID: <BANLkTi=WVTGcGkUXjkuPYcxhMY0a5KPB7g@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTi%3DWVTGcGkUXjkuPYcxhMY0a5KPB7g%40mail.gmail.com
In-Reply-To: <4E005404.5010901@drmicha.warpmail.net>

```
> 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.

> 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, 2011-06-21 09:38

Subject: Re: corrupted Git repository
Message-ID: <4E006682.80101@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4E006682.80101%40drmicha.warpmail.net
In-Reply-To: <BANLkTi=WVTGcGkUXjkuPYcxhMY0a5KPB7g@mail.gmail.com>

```
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

```

## Kasra Khosoussi, 2011-06-21 10:10

Subject: Re: corrupted Git repository
Message-ID: <BANLkTi=GdEfXnAGa6V-33wqX2C-2x-9JQQ@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTi%3DGdEfXnAGa6V-33wqX2C-2x-9JQQ%40mail.gmail.com
In-Reply-To: <4E006682.80101@drmicha.warpmail.net>

```
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:
> 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, 2011-06-21 10:39

Subject: Re: corrupted Git repository
Message-ID: <20110621103947.GA30147@LK-Perkele-VI.localdomain>
URL: https://gitlist.dev/e/20110621103947.GA30147%40LK-Perkele-VI.localdomain
In-Reply-To: <BANLkTi=GdEfXnAGa6V-33wqX2C-2x-9JQQ@mail.gmail.com>

```
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

```

## Kasra Khosoussi, 2011-06-21 10:40

Subject: Re: corrupted Git repository
Message-ID: <BANLkTimQarJ=m7OSVg-uC_48eh3PxQ3cKw@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTimQarJ%3Dm7OSVg-uC_48eh3PxQ3cKw%40mail.gmail.com
In-Reply-To: <20110621103947.GA30147@LK-Perkele-VI.localdomain>

```
Thanks for your help.

On Tue, Jun 21, 2011 at 3:09 PM, Ilari Liusvaara
<ilari.liusvaara@elisanet.fi> wrote:
> 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, 2011-06-21 13:47

Subject: Re: corrupted Git repository
Message-ID: <4E00A0E1.8000006@viscovery.net>
URL: https://gitlist.dev/e/4E00A0E1.8000006%40viscovery.net
In-Reply-To: <BANLkTi=GdEfXnAGa6V-33wqX2C-2x-9JQQ@mail.gmail.com>

```
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, 2011-06-21 14:26

Subject: Re: corrupted Git repository
Message-ID: <BANLkTi=6jt7Z3fvK++ontW=F9AJbmEr9Qg@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTi%3D6jt7Z3fvK%2B%2BontW%3DF9AJbmEr9Qg%40mail.gmail.com
In-Reply-To: <4E00A0E1.8000006@viscovery.net>

```
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:
> 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, 2011-06-21 14:32

Subject: Re: corrupted Git repository
Message-ID: <20110621143211.GA4910@bee.lab.cmartin.tk>
URL: https://gitlist.dev/e/20110621143211.GA4910%40bee.lab.cmartin.tk
In-Reply-To: <BANLkTi=6jt7Z3fvK++ontW=F9AJbmEr9Qg@mail.gmail.com>

```
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

```

## Kasra Khosoussi, 2011-06-21 14:59

Subject: Re: corrupted Git repository
Message-ID: <BANLkTinaMfD4YG_Rx1OhixoX7XuPmaiaMQ@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTinaMfD4YG_Rx1OhixoX7XuPmaiaMQ%40mail.gmail.com
In-Reply-To: <20110621143211.GA4910@bee.lab.cmartin.tk>

```
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:
> 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
>

```
