{"thread":{"id":"2073","subject":"How to restore the original head after `git-reset --hard master^`","startedAt":"2005-10-11T15:12:26Z","lastAt":"2005-10-11T21:37:40Z","messageCount":5,"participants":["Ben Lau","Linus Torvalds","Daniel Barkalow","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"9963","messageId":"434BD65A.9000108@ust.hk","threadId":"2073","inReplyTo":null,"subject":"How to restore the original head after `git-reset --hard master^`","fromName":"Ben Lau","fromEmail":"benlau@ust.hk","sentAt":"2005-10-11T15:12:26Z","receivedAt":"2005-10-11T15:12:26Z","isPatch":false,"sender":{"key":"benlau@ust.hk","avatar":null},"body":"Hi all,\n\n   After involves the command `git-reset --hard master^` in a \nrepository, the working\ntree , current head and index are restored to the parent of master. That \nincludes\nthe content of '.git/refs/head/master'. Although the original commit \nobject is still existed\n, I couldn't find it back.\n\n  Is there anyway to recover the original master branch ? or I have to \nrestore the branch\nmanually by finding out all the child of current head? If that is the \nsolution , what command\ncould provide this information?\n\nThanks\n"},{"id":"9965","messageId":"Pine.LNX.4.64.0510110856520.14597@g5.osdl.org","threadId":"2073","inReplyTo":"434BD65A.9000108@ust.hk","subject":"Re: How to restore the original head after `git-reset --hard master^`","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-10-11T15:59:05Z","receivedAt":"2005-10-11T15:59:05Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Tue, 11 Oct 2005, Ben Lau wrote:\n> \n>   After involves the command `git-reset --hard master^` in a repository, \n> the working tree , current head and index are restored to the parent of \n> master. That includes the content of '.git/refs/head/master'. Although \n> the original commit object is still existed , I couldn't find it back.\n> \n>  Is there anyway to recover the original master branch ?\n\nJust run \"git-fsck-objects\" and look at any dangling commits. The commit \nand related objects are still there (unless you've run \"git prune\"), so \nonce you find the name of it, you're all done.\n\nFirst check that you  have the right one by doing\n\n\tgit log <name-you-found>\n\nand if that looks right, you can just do\n\n\tgit reset --hard <name-you-found>\n\nand you should be back in business.\n\n\t\tLinus\n"},{"id":"9967","messageId":"Pine.LNX.4.63.0510111240410.23242@iabervon.org","threadId":"2073","inReplyTo":"Pine.LNX.4.64.0510110856520.14597@g5.osdl.org","subject":"Re: How to restore the original head after `git-reset --hard master^`","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-10-11T16:58:03Z","receivedAt":"2005-10-11T16:58:03Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Tue, 11 Oct 2005, Linus Torvalds wrote:\n\n> On Tue, 11 Oct 2005, Ben Lau wrote:\n> > \n> >   After involves the command `git-reset --hard master^` in a repository, \n> > the working tree , current head and index are restored to the parent of \n> > master. That includes the content of '.git/refs/head/master'. Although \n> > the original commit object is still existed , I couldn't find it back.\n> > \n> >  Is there anyway to recover the original master branch ?\n> \n> Just run \"git-fsck-objects\" and look at any dangling commits. The commit \n> and related objects are still there (unless you've run \"git prune\"), so \n> once you find the name of it, you're all done.\n\nThat reminds me: if you lose all of your refs, it's hard to get them back, \nbecause git-fsck-objects aborts if you don't specify any heads or have any \nrefs. Is there some reason for this check?\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"9968","messageId":"Pine.LNX.4.64.0510111003180.14597@g5.osdl.org","threadId":"2073","inReplyTo":"Pine.LNX.4.63.0510111240410.23242@iabervon.org","subject":"Re: How to restore the original head after `git-reset --hard master^`","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-10-11T17:04:25Z","receivedAt":"2005-10-11T17:04:25Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Tue, 11 Oct 2005, Daniel Barkalow wrote:\n> \n> That reminds me: if you lose all of your refs, it's hard to get them back, \n> because git-fsck-objects aborts if you don't specify any heads or have any \n> refs. Is there some reason for this check?\n\n\"git prune\" is the reason for that check.  Pruning your whole object store \nis likely not what you want ;)\n\nYou might make it abort only when \"--unreachable\" has been specified..\n\n\t\tLinus\n"},{"id":"9980","messageId":"7vpsqbspjv.fsf@assigned-by-dhcp.cox.net","threadId":"2073","inReplyTo":"434BD65A.9000108@ust.hk","subject":"Re: How to restore the original head after `git-reset --hard master^`","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-10-11T21:37:40Z","receivedAt":"2005-10-11T21:37:40Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ben Lau <benlau@ust.hk> writes:\n\n>   After involves the command `git-reset --hard master^` in a \n> repository, the working\n> tree , current head and index are restored to the parent of master. That \n> includes\n> the content of '.git/refs/head/master'. Although the original commit \n> object is still existed\n> , I couldn't find it back.\n\nI think you can find it in .git/ORIG_HEAD.\n"}]}