# How to restore the original head after `git-reset --hard master^`

5 messages from 2005-10-11 to 2005-10-11. Participants: Ben Lau, Linus Torvalds, Daniel Barkalow, Junio C Hamano.
Thread: https://gitlist.dev/t/2073

## Ben Lau, 2005-10-11 15:12

Subject: How to restore the original head after `git-reset --hard master^`
Message-ID: <434BD65A.9000108@ust.hk>
URL: https://gitlist.dev/e/434BD65A.9000108%40ust.hk

```
Hi all,

   After involves the command `git-reset --hard master^` in a 
repository, the working
tree , current head and index are restored to the parent of master. That 
includes
the content of '.git/refs/head/master'. Although the original commit 
object is still existed
, I couldn't find it back.

  Is there anyway to recover the original master branch ? or I have to 
restore the branch
manually by finding out all the child of current head? If that is the 
solution , what command
could provide this information?

Thanks

```

## Linus Torvalds, 2005-10-11 15:59

Subject: Re: How to restore the original head after `git-reset --hard master^`
Message-ID: <Pine.LNX.4.64.0510110856520.14597@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0510110856520.14597%40g5.osdl.org
In-Reply-To: <434BD65A.9000108@ust.hk>

```


On Tue, 11 Oct 2005, Ben Lau wrote:
> 
>   After involves the command `git-reset --hard master^` in a repository, 
> the working tree , current head and index are restored to the parent of 
> master. That includes the content of '.git/refs/head/master'. Although 
> the original commit object is still existed , I couldn't find it back.
> 
>  Is there anyway to recover the original master branch ?

Just run "git-fsck-objects" and look at any dangling commits. The commit 
and related objects are still there (unless you've run "git prune"), so 
once you find the name of it, you're all done.

First check that you  have the right one by doing

	git log <name-you-found>

and if that looks right, you can just do

	git reset --hard <name-you-found>

and you should be back in business.

		Linus

```

## Daniel Barkalow, 2005-10-11 16:58

Subject: Re: How to restore the original head after `git-reset --hard master^`
Message-ID: <Pine.LNX.4.63.0510111240410.23242@iabervon.org>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0510111240410.23242%40iabervon.org
In-Reply-To: <Pine.LNX.4.64.0510110856520.14597@g5.osdl.org>

```
On Tue, 11 Oct 2005, Linus Torvalds wrote:

> On Tue, 11 Oct 2005, Ben Lau wrote:
> > 
> >   After involves the command `git-reset --hard master^` in a repository, 
> > the working tree , current head and index are restored to the parent of 
> > master. That includes the content of '.git/refs/head/master'. Although 
> > the original commit object is still existed , I couldn't find it back.
> > 
> >  Is there anyway to recover the original master branch ?
> 
> Just run "git-fsck-objects" and look at any dangling commits. The commit 
> and related objects are still there (unless you've run "git prune"), so 
> once you find the name of it, you're all done.

That reminds me: if you lose all of your refs, it's hard to get them back, 
because git-fsck-objects aborts if you don't specify any heads or have any 
refs. Is there some reason for this check?

	-Daniel
*This .sig left intentionally blank*

```

## Linus Torvalds, 2005-10-11 17:04

Subject: Re: How to restore the original head after `git-reset --hard master^`
Message-ID: <Pine.LNX.4.64.0510111003180.14597@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0510111003180.14597%40g5.osdl.org
In-Reply-To: <Pine.LNX.4.63.0510111240410.23242@iabervon.org>

```


On Tue, 11 Oct 2005, Daniel Barkalow wrote:
> 
> That reminds me: if you lose all of your refs, it's hard to get them back, 
> because git-fsck-objects aborts if you don't specify any heads or have any 
> refs. Is there some reason for this check?

"git prune" is the reason for that check.  Pruning your whole object store 
is likely not what you want ;)

You might make it abort only when "--unreachable" has been specified..

		Linus

```

## Junio C Hamano, 2005-10-11 21:37

Subject: Re: How to restore the original head after `git-reset --hard master^`
Message-ID: <7vpsqbspjv.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vpsqbspjv.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <434BD65A.9000108@ust.hk>

```
Ben Lau <benlau@ust.hk> writes:

>   After involves the command `git-reset --hard master^` in a 
> repository, the working
> tree , current head and index are restored to the parent of master. That 
> includes
> the content of '.git/refs/head/master'. Although the original commit 
> object is still existed
> , I couldn't find it back.

I think you can find it in .git/ORIG_HEAD.

```
