{"thread":{"id":"17610","subject":"can git reset or checkout be reverted?","startedAt":"2009-02-06T14:19:40Z","lastAt":"2009-02-07T05:31:38Z","messageCount":5,"participants":["bill lam","Jakub Narebski","Matthieu Moy","Sitaram Chamarty"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"103485","messageId":"20090206141940.GB7231@b2j","threadId":"17610","inReplyTo":null,"subject":"can git reset or checkout be reverted?","fromName":"bill lam","fromEmail":"cbill.lam@gmail.com","sentAt":"2009-02-06T14:19:40Z","receivedAt":"2009-02-06T14:19:40Z","isPatch":false,"sender":{"key":"cbill.lam@gmail.com","avatar":null},"body":"If I want to recall a old version of testing by\n\ngit reset --hard sha1\nor\ngit checkout sha1\n\nthen git log does not show anything beyond that commit. It does give\nsome warning and recommend -b switch next time.  If I only do that by\naccident or ignorance.  How to revert to the original HEAD?\n\n-- \nregards,\n====================================================\nGPG key 1024D/4434BAB3 2008-08-24\ngpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3\n唐詩274 韓翃  寒食\n    春城無處不飛花  寒食東風御柳斜  日暮漢宮傳蠟燭  輕煙散入五侯家\n"},{"id":"103492","messageId":"vpqiqnnbp7x.fsf@bauges.imag.fr","threadId":"17610","inReplyTo":"20090206141940.GB7231@b2j","subject":"Re: can git reset or checkout be reverted?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2009-02-06T14:43:30Z","receivedAt":"2009-02-06T14:43:30Z","isPatch":false,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"bill lam <cbill.lam@gmail.com> writes:\n\n> If I want to recall a old version of testing by\n>\n> git reset --hard sha1\n\ngit reset is mostly about changing the place the current branch points\nto. If you checkout branch master, and then say \"git reset --hard\nsha1\", then, you say \"OK, from now, the tip of branch master will be\nsha1\".\n\n> git checkout sha1\n\nThis is the one you were looking for.\n\n> then git log does not show anything beyond that commit. It does give\n> some warning and recommend -b switch next time.\n\nIt does not \"recommand\" it, it says that _if_ you wanted to create a\nbranch, you could have done it with -b.\n\n> If I only do that by accident or ignorance. How to revert to the\n> original HEAD?\n\nCase 1: you used checkout. Then, the branch still points to where you\nwere before the \"checkout\". Just \"git checkout master\", or replace\nmaster with where you used to be.\n\nIn any case: the reflog can help you. It keeps track of where your\nHEAD and other references (branches, ...) have been pointing before.\n\ngit reflog\ngit reflog show master\n\nto see it, and this allows you to say things like\n\ngit checkout HEAD@{1}\ngit reset HEAD@{1}\n\nThe HEAD@{1} means \"where HEAD used to be one move ago\".\n\n-- \nMatthieu\n"},{"id":"103491","messageId":"m3vdrnvczd.fsf@localhost.localdomain","threadId":"17610","inReplyTo":"20090206141940.GB7231@b2j","subject":"Re: can git reset or checkout be reverted?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-02-06T14:47:40Z","receivedAt":"2009-02-06T14:47:40Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"bill lam <cbill.lam@gmail.com> writes:\n\n> If I want to recall a old version of testing by\n> \n> git reset --hard sha1\n> or\n> git checkout sha1\n> \n> then git log does not show anything beyond that commit. It does give\n> some warning and recommend -b switch next time.  If I only do that by\n> accident or ignorance.  How to revert to the original HEAD?\n\n  git checkout ORIG_HEAD\n\nor\n\n  git checkout HEAD@{1}\n\nYou can check it out wrt. second form using \"git reflog\" (\"git log -g\").\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"103517","messageId":"slrngoonqk.urh.sitaramc@sitaramc.homelinux.net","threadId":"17610","inReplyTo":"20090206141940.GB7231@b2j","subject":"Re: can git reset or checkout be reverted?","fromName":"Sitaram Chamarty","fromEmail":"sitaramc@gmail.com","sentAt":"2009-02-06T16:03:32Z","receivedAt":"2009-02-06T16:03:32Z","isPatch":false,"sender":{"key":"sitaramc@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43316?v=4"},"body":"On 2009-02-06, bill lam <cbill.lam@gmail.com> wrote:\n> If I want to recall a old version of testing by\n>\n> git reset --hard sha1\n> or\n> git checkout sha1\n>\n> then git log does not show anything beyond that commit. It does give\n> some warning and recommend -b switch next time.  If I only do that by\n> accident or ignorance.  How to revert to the original HEAD?\n\nAs others have said: reflog.\n\nI just wanted to add, I've had a lot of luck using reflog's\n@{now} feature:\n\n    git reflog show @{now}\n\nCoupled with a vague recollection of what action I did at\nwhat time, this has saved me a few times, and if I've been\njumping around branches as well, then:\n\n    git reflog show HEAD@{now}\n\nAnother good one is:\n\n    git show-branch --sha1-name -g=5\n\n(or some larger value depending on how big your xterm is.)\nThis is particularly useful when I've done a lot of 'git\ncommit --amend' or rebases; the top most '+' sign in each\ncolumn, starting from the left, is your reflog -- I don't\nknow who came up with this design but it's amazing how much\nuseful information is condensed into that display.\n"},{"id":"103582","messageId":"20090207053137.GA7240@b2j","threadId":"17610","inReplyTo":"slrngoonqk.urh.sitaramc@sitaramc.homelinux.net","subject":"Re: can git reset or checkout be reverted?","fromName":"bill lam","fromEmail":"cbill.lam@gmail.com","sentAt":"2009-02-07T05:31:38Z","receivedAt":"2009-02-07T05:31:38Z","isPatch":false,"sender":{"key":"cbill.lam@gmail.com","avatar":null},"body":"Sitaram Matthieu Jakub\n\nMany thanks for help!\n\n-- \nregards,\n====================================================\nGPG key 1024D/4434BAB3 2008-08-24\ngpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3\n唐詩281 劉禹錫  春詞\n    新妝宜面下朱樓  深鎖春光一院愁  行到中庭數花朵  蜻蜓飛上玉搔頭\n"}]}