Undo a git stash

Git

Git Problem Overview


I just did a stash in a project that I haven't commit. Is there a way to go back to the state before I stashed? How could I do this? I've closed the terminal and my laptop is shut down. I've done some researched and it seems there's no way to do this.

Git Solutions


Solution 1 - Git

You can just run:

git stash pop

and it will unstash your changes.

If you want to preserve the state of files (staged vs. working), use

git stash apply --index

Solution 2 - Git

git stash list to list your stashed changes.

git stash show to see what n is in the below commands.

git stash apply to apply the most recent stash.

git stash apply stash@{n} to apply an older stash.

https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning

Solution 3 - Git

This will also restore the staging directory:

git stash apply --index

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaditView Question on Stackoverflow
Solution 1 - Gitziad-saabView Answer on Stackoverflow
Solution 2 - GitOmnipotentEntityView Answer on Stackoverflow
Solution 3 - GitwisbuckyView Answer on Stackoverflow