Skip to content

Instantly share code, notes, and snippets.

@ajay-cz
Forked from joseluisq/stash_dropped.md
Created September 8, 2019 07:21
Show Gist options
  • Save ajay-cz/ed1bb21ab191a14b1d25d9ae705a034c to your computer and use it in GitHub Desktop.
Save ajay-cz/ed1bb21ab191a14b1d25d9ae705a034c to your computer and use it in GitHub Desktop.
How to recover a dropped stash in Git?

How to recover a dropped stash in Git?

1. Find the stash commits:

git log --graph --oneline --decorate ( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )

This will show you all the commits at the tips of your commit graph which are no longer referenced from any branch or tag – every lost commit, including every stash commit you’ve ever created, will be somewhere in that graph.

2. Once you know the hash of the commit you want, you can apply it as a stash:

git stash apply YOUR_WIP_COMMIT_HASH

Note: The commit message will only be in this form (starting with "WIP on") if you did not supply a message when you did git stash.

Source: View the complete answer at https://stackoverflow.com/a/91795/2510591

@ajay-cz
Copy link
Author

ajay-cz commented Sep 8, 2019

git log --graph --oneline --decorate $( git fsck --no-reflog | %{ $_.Split(' ')[2]; } )
https://gist.github.com/joseluisq/7f0f1402f05c45bac10814a9e38f81bf#gistcomment-2922040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment