Search code examples
ruby-on-railsrubygitgit-stash

git: temporarily store current files - and return them


I know git stash, but somehow either I am doing something wrong or my problem is not as common as I think.

Scenario: I am coding, committed and pushed a version, doing further code, then to make a decision I would like to test something. For that, I'd love to save the current local files away and return to that state later on to try another solution. Note: in an intermediate un-committed state. Something one would do normally by zipping the project folder and restoring it later.

git stash for me has the crux, that I cannot tell it to simply re-apply the stashed content, ignore anything else, simply recover what was stashed. With git stash apply --force I get (of course) warnings that files are not committed.

Any help?


Solution

  • Use git checkout instead of git stash apply:

    $ git checkout stash -- .
    

    This will restore all the files in the current directory to their stashed version.