threads / discuss / 2073

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

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

## tl;dr

5 messages between Oct 11, 2005 and Oct 11, 2005.

replies: 4people: 4as markdown or json

Ben Lau· Oct 11, 2005, 15:12 UTC · lore
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· Oct 11, 2005, 15:59 UTC · re: Ben Lau · lore

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

On Tue, 11 Oct 2005, Ben Lau wrote:
Show 7 quoted lines
> 
>   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· Oct 11, 2005, 16:58 UTC · re: Linus Torvalds · lore

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

On Tue, 11 Oct 2005, Linus Torvalds wrote:
Show 12 quoted lines
> 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· Oct 11, 2005, 17:04 UTC · re: Daniel Barkalow · lore

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

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· Oct 11, 2005, 21:37 UTC · re: Ben Lau · lore

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

Ben Lau <benlau@ust.hk> writes:
Show 7 quoted lines
>   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.

← back to recent threads