🔧 How to Recover a Lost Git Stash
You're exactly right. That's a great way to recover a stash that was accidentally dropped or lost (for instance, after a git stash pop that resulted in a conflict).
Here’s a breakdown of the process you described and why it works.
1. First Check: git stash list
You should always start with this command. It shows you the stack of all stashes Git is actively managing.
If you see your missing stash here (e.g., stash@{2}: WIP on main: ...), you don't need the reflog. You can just apply it directly using its identifier:
2. If It's Not in the List: git reflog
If git stash list doesn't show your stash, it means the reference to it was deleted (like with git stash drop or a completed git stash pop). However, the stash itself is just a commit, and it likely still exists in your repository for a while before being garbage-collected.
This is where git reflog comes in. It shows a log of where your HEAD and branches have been.
When you run this, you're looking for the commit hash associated with the stash. Stash commits are typically labeled with a message like "WIP on [branch-name]: [commit-message]" or just "stash".
3. Recover the Stash: git stash apply
Once you identify the commit hash (e.g., e8f09d4) from the reflog, you can apply it just like a regular stash:
This will re-apply the changes from that lost stash to your current working directory.