Quantcast
Channel: How do I recover a dropped stash in Git? - Stack Overflow
Viewing all articles
Browse latest Browse all 52

Answer by Brad Feehan for How to recover a dropped stash in Git?

$
0
0

The accepted answer by Aristotle will show all reachable commits, including non-stash-like commits. To filter out the noise:

git fsck --no-reflog | \awk '/dangling commit/ {print $3}' | \xargs git log --no-walk --format="%H" \  --grep="WIP on" --min-parents=3 --max-parents=3

This will only include commits which have exactly 3 parent commits (which a stash will have), and whose message includes "WIP on".

Keep in mind, that if you saved your stash with a message (e.g. git stash save "My newly created stash"), this will override the default "WIP on..." message.

You can display more information about each commit, e.g. display the commit message, or pass it to git stash show:

git fsck --no-reflog | \awk '/dangling commit/ {print $3}' | \xargs git log --no-walk --format="%H" \  --grep="WIP on" --min-parents=3 --max-parents=3 | \xargs -n1 -I '{}' bash -c "\  git log -1 --format=medium --color=always '{}'; echo; \  git stash show --color=always '{}'; echo; echo" | \less -R

Viewing all articles
Browse latest Browse all 52

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>