threads / discuss / 26091

how to recover a repository

Subject: how to recover a repository

## tl;dr

5 messages between Dec 17, 2010 and Dec 17, 2010.

replies: 4people: 3as markdown or json

david@lang.hm· Dec 17, 2010, 04:28 UTC · lore

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· Dec 17, 2010, 04:45 UTC · re: david@lang.hm · lore

Re: how to recover a repository

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· Dec 17, 2010, 20:20 UTC · re: Jonathan Nieder · lore

Re: how to recover a repository

On Thu, 16 Dec 2010, Jonathan Nieder wrote:
Show 15 quoted lines
> 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
Show 5 quoted lines
> 4. git reset;	# (alas, the old index file is gone)
> 5. git diff; gitk --all
>
> See gitrepository-layout(7) for details.
>
Jeff King· Dec 17, 2010, 21:22 UTC · re: david@lang.hm · lore

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
david@lang.hm· Dec 17, 2010, 22:30 UTC · re: Jeff King · lore

Re: how to recover a repository

thanks, that appears to have worked.
David Lang
On Fri, 17 Dec 2010, Jeff King wrote:
Show 17 quoted lines
> 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
>

← back to recent threads