{"thread":{"id":"13520","subject":"Newbie question: Is it possible to undo a stash?","startedAt":"2008-05-14T19:56:52Z","lastAt":"2008-05-14T20:51:40Z","messageCount":3,"participants":["Iván V.","Jakub Narebski","Jean-Luc Herren"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"76982","messageId":"509f40850805141256gce6ac1brf5ced6436f81dae8@mail.gmail.com","threadId":"13520","inReplyTo":null,"subject":"Newbie question: Is it possible to undo a stash?","fromName":"Iván V.","fromEmail":"elterrible@ivanyvenian.com","sentAt":"2008-05-14T19:56:52Z","receivedAt":"2008-05-14T19:56:52Z","isPatch":false,"sender":{"key":"elterrible@ivanyvenian.com","avatar":null},"body":"Hi,\n\nI just did a git stash, and then changed my mind and ran git apply,\nthinking that would get me back to where I was...\n\nNow I have lots of conflicting merges and files that came back from\nthe dead (and some files seem lost)... I've been trying to go step by\nstep to try to get the tree to where it was, but it's very\ncomplicated, so I was wondering if there is anything I can do to get\nmy working tree exactly to where it was before I ran git stash...\n\nThanks!\n"},{"id":"76990","messageId":"m3y76c4nxv.fsf@localhost.localdomain","threadId":"13520","inReplyTo":"509f40850805141256gce6ac1brf5ced6436f81dae8@mail.gmail.com","subject":"Re: Newbie question: Is it possible to undo a stash?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-05-14T20:42:56Z","receivedAt":"2008-05-14T20:42:56Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"\"Iván V.\" <elterrible@ivanyvenian.com> writes:\n\n> I just did a git stash, and then changed my mind and ran git apply,\n> thinking that would get me back to where I was...\n\nYou meant \"git stash apply\" here, didn't you?\n \n> Now I have lots of conflicting merges and files that came back from\n> the dead (and some files seem lost)... I've been trying to go step by\n> step to try to get the tree to where it was, but it's very\n> complicated, so I was wondering if there is anything I can do to get\n> my working tree exactly to where it was before I ran git stash...\n\nTo get your working tree and index to exact state as it was before\ngit-stash, you have first to bring current HEAD to the state it was\nwhen you did the stash.  So if you changed branch, you have to change\nit back; if you did any commits, you have to rewind (reset) it.\n\nIf the \"base\" state isn't the same as it was during \"git stash\", then\n\"git stash apply\" would have to do a merge... which can fail...\n\n\nP.S. Please provide with the exact (best if minimal) sequence of\ncommands, if you want for us to dianoze if there is a bug in git, or\nuser error.\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"76991","messageId":"482B50DC.3020400@gmx.ch","threadId":"13520","inReplyTo":"509f40850805141256gce6ac1brf5ced6436f81dae8@mail.gmail.com","subject":"Re: Newbie question: Is it possible to undo a stash?","fromName":"Jean-Luc Herren","fromEmail":"jlh@gmx.ch","sentAt":"2008-05-14T20:51:40Z","receivedAt":"2008-05-14T20:51:40Z","isPatch":false,"sender":{"key":"jlh@gmx.ch","avatar":null},"body":"Hello!\n\nIván V. wrote:\n> I just did a git stash, and then changed my mind and ran git apply,\n> thinking that would get me back to where I was...\n\nCertainly you mean \"git stash apply\".  \"git apply\" is something\ndifferent.\n\n> Now I have lots of conflicting merges and files that came back from\n> the dead (and some files seem lost)... I've been trying to go step by\n> step to try to get the tree to where it was, but it's very\n> complicated, so I was wondering if there is anything I can do to get\n> my working tree exactly to where it was before I ran git stash...\n\ngit stash pop --index\n\nI think that should get you exactly where you were before \"git\nstash\".  The --index makes it also restore the index, which\nwouldn't happen by default.  Using 'pop' instead of 'apply' makes\nit remove the stash after re-applying it.\n\njlh\n"}]}