Search code examples
gitversion-controlpatchgit-stash

save git stash revision long term


How do I

"Save" a git stash and store it away long terms such that I can access it in the future (perhaps save it in some patch file) even after the stash itself is cleared. IE. how do I save a certain stash into a file such that I can clear the current stashes and that nothing will show up if I do git stash list and yet I will still be able to access the saved stash revision in the future if I want to


Solution

  • You asked for a file, but I would use git to save the change set -- much easier to keep track of than a file.

    Create a new branch

    git checkout -b saved_stash
    

    pop the stash, add and commit

    git stash pop
    git add .
    git commit -m 'save stash for later'
    

    When you want to use it again checkout the branch, reset the commit and add to stash again

    git checkout saved_stash
    git reset --soft HEAD~1
    git stash
    

    At this point you should have the same stash state you originaly saved.

    (typed on the run, commands may be off slightly -- I hope only slightly)