Skip to content

Instantly share code, notes, and snippets.

@HoangTran0410
Forked from joseluisq/stash_dropped.md
Created August 26, 2020 10:10
Show Gist options
  • Save HoangTran0410/d153de7236c2719b128d3337c03d49cc to your computer and use it in GitHub Desktop.
Save HoangTran0410/d153de7236c2719b128d3337c03d49cc 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.

bash/sh shell users: Version above is for Fish shell, so if you are Bash/SH user just add a $ sign before to the left parenthesis.

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_HERE

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

Bonus

If you are Fish shell user, you can take a look at GitNow which is a tool to perform faster Git operations and that can also stash your changes for you.

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