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.
Asked
Active
Viewed 4.9e+01k times
511
-
Related post [here](https://stackoverflow.com/q/19003009/465053). – RBT Sep 05 '17 at 06:25
-
To clarify, because I do think this is confusing to people new-to-version-control: The stash is changes made to files. So if you closed your terminal, or shutdown your system, they would not have additional effects on your situation. You simply need to terminal-shell to the same place (in the git repository), and then sort out your next step in handling the stash. – benc May 18 '22 at 20:15
3 Answers
957
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
-
15Well, not quite. It will not reset what is in the staging directory, so you will have to restage all that (which can be annoying if you had just done a complex git add -p – Nick Jan 02 '13 at 17:31
-
Didn't work for me. I got an error: `mymodule/MyClass.java: needs merge - unable to refresh index`. Avoiding a manual merge was precisely my goal when using `git stash pop`... – TanguyP Sep 18 '15 at 15:10
-
Saved my life. I though my all changes are gone & need to all things again. Thanks – Jackson Mar 31 '20 at 08:30
-
-
1@theonlygusti I don't remember what my solution was. I was still quite new to Git at the time, and I guess what happened is that I stashed some changes, then did some more changes which conflicted with the stashed changes, then tried to `git stash pop`. In that case, I think a manual resolution of conflicts is the only way, unless you're willing to discard the newer changes before doing a `git stash pop`. – TanguyP Aug 22 '20 at 16:34
-
Thanks. I was trying to use Visual Studio git capabilities for the first time and hit stash at the end of my project. Boom. project gone. And git was not in Visual Studio to pop the stash. git stash pop saved my bacon! – Sting Oct 12 '20 at 18:06
178
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
OmnipotentEntity
- 15,783
- 5
- 62
- 95
-
1also "git stash show" after "git stash list" just to round out this excellent answer and better identify what to replace n with. Turns out I have stuff stashed from files that don't exist any longer! – JimLohse Jan 15 '16 at 22:53