Search code examples
gitgit-stash

Git stash reset version to previous. How do I get my work back?


I am working with git for a college project and it has been a tricky learning curve. Last night I was trying to upload my work into the main tree and I did first a 'git stash' in terminal and it seems to have reset my code to the previous version. I am a git novice. Is there a way that I can get my work back?

Heres what I put in to terminal and what it read out:

$ git stash
Saved working directory and index state WIP on master: 00b2935 undated with desktop(unfinished)
HEAD is now at 00b2935 undated with desktop(unfinished)
[  ][ darraghkenny ][][master=][ ~/projects/RosettaFoundation-new-design ]
$ 

Solution

  • you can type

    $ git stash list
    

    to print out a list of all previously saved stashes.

    Chronologically, you can fetch them back using

    $ git stash apply stash@{0}
    

    being the latest one, stash@{1} being the penultimate one, and stash@{N} for subsequent stashes