# how to recover a repository

5 messages from 2010-12-17 to 2010-12-17. Participants: david@lang.hm, Jonathan Nieder, Jeff King.
Thread: https://gitlist.dev/t/26091

## david@lang.hm, 2010-12-17 04:28

Subject: how to recover a repository
Message-ID: <alpine.DEB.2.00.1012162024020.22269@asgard.lang.hm>
URL: https://gitlist.dev/e/alpine.DEB.2.00.1012162024020.22269%40asgard.lang.hm

```
I managed to do a 'rm *' in the .git directory (the usual sort of 
fat-fingering when cleaning up after another mistake)

the subdirectories are still there.

this is just a local repository, it won't kill me if I loose everything 
(as I still have the most recent working files), but I'd like to recover 
what I can.

what can I do to get things back in a usable state?

David Lang

```

## Jonathan Nieder, 2010-12-17 04:45

Subject: Re: how to recover a repository
Message-ID: <20101217044530.GA8590@burratino>
URL: https://gitlist.dev/e/20101217044530.GA8590%40burratino
In-Reply-To: <alpine.DEB.2.00.1012162024020.22269@asgard.lang.hm>

```
Hi David,

david@lang.hm wrote:

> I managed to do a 'rm *' in the .git directory (the usual sort of
> fat-fingering when cleaning up after another mistake)
> 
> the subdirectories are still there.

I'd suggest:

 1. Make a backup!
 2. From the worktree (i.e. parent to the .git directory),
    run "git init".
 3. git update-ref HEAD refs/heads/(branch you were on)
 4. git reset;	# (alas, the old index file is gone)
 5. git diff; gitk --all

See gitrepository-layout(7) for details.

```

## david@lang.hm, 2010-12-17 20:20

Subject: Re: how to recover a repository
Message-ID: <alpine.DEB.2.00.1012171218450.18272@asgard.lang.hm>
URL: https://gitlist.dev/e/alpine.DEB.2.00.1012171218450.18272%40asgard.lang.hm
In-Reply-To: <20101217044530.GA8590@burratino>

```
On Thu, 16 Dec 2010, Jonathan Nieder wrote:

> Hi David,
>
> david@lang.hm wrote:
>
>> I managed to do a 'rm *' in the .git directory (the usual sort of
>> fat-fingering when cleaning up after another mistake)
>>
>> the subdirectories are still there.
>
> I'd suggest:
>
> 1. Make a backup!
> 2. From the worktree (i.e. parent to the .git directory),
>    run "git init".
> 3. git update-ref HEAD refs/heads/(branch you were on)

I was on the default branch but if I do 'git update-ref HEAD 
refs/heads/master' I get an error 'not a valid SHA1'

.git/refs/heads is empty

.git/logs/HEAD looks like it shows all the commits in it properly

David Lang

> 4. git reset;	# (alas, the old index file is gone)
> 5. git diff; gitk --all
>
> See gitrepository-layout(7) for details.
>

```

## Jeff King, 2010-12-17 21:22

Subject: Re: how to recover a repository
Message-ID: <20101217212201.GC11511@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20101217212201.GC11511%40sigill.intra.peff.net
In-Reply-To: <alpine.DEB.2.00.1012171218450.18272@asgard.lang.hm>

```
On Fri, Dec 17, 2010 at 12:20:56PM -0800, david@lang.hm wrote:

> >3. git update-ref HEAD refs/heads/(branch you were on)
> 
> I was on the default branch but if I do 'git update-ref HEAD
> refs/heads/master' I get an error 'not a valid SHA1'

That should be "git symbolic-ref HEAD refs/heads/master".

-Peff

```

## david@lang.hm, 2010-12-17 22:30

Subject: Re: how to recover a repository
Message-ID: <alpine.DEB.2.00.1012171430270.18272@asgard.lang.hm>
URL: https://gitlist.dev/e/alpine.DEB.2.00.1012171430270.18272%40asgard.lang.hm
In-Reply-To: <20101217212201.GC11511@sigill.intra.peff.net>

```
thanks, that appears to have worked.

David Lang

On Fri, 17 Dec 2010, Jeff King wrote:

> Date: Fri, 17 Dec 2010 16:22:02 -0500
> From: Jeff King <peff@peff.net>
> To: david@lang.hm
> Cc: Jonathan Nieder <jrnieder@gmail.com>, git@vger.kernel.org
> Subject: Re: how to recover a repository
> 
> On Fri, Dec 17, 2010 at 12:20:56PM -0800, david@lang.hm wrote:
>
>>> 3. git update-ref HEAD refs/heads/(branch you were on)
>>
>> I was on the default branch but if I do 'git update-ref HEAD
>> refs/heads/master' I get an error 'not a valid SHA1'
>
> That should be "git symbolic-ref HEAD refs/heads/master".
>
> -Peff
>

```
