0

I did git stash from the branch. How to get my files before git stash?

git stash
git checkout other-branch
git stash pop

I did not save them before.

ibragim
  • 5
  • 3
  • 3
    Could you clarify? What do you get, what did you expect? – Chris Maes Jun 30 '20 at 06:09
  • You generally _can't_ undo the changes made to your working directory by applying the stash. – Tim Biegeleisen Jun 30 '20 at 06:09
  • Save *them*? Save what? Which files? `git stash` makes a stash copy, `git stash pop` applies the stash to your working folder, inbetween you checked out a branch, which files do you want brought back? – Lasse V. Karlsen Jun 30 '20 at 07:24
  • Does this answer your question? [How to recover stashed uncommitted changes](https://stackoverflow.com/questions/19003009/how-to-recover-stashed-uncommitted-changes) – Qumber Jun 30 '20 at 08:09

1 Answers1

0

If you mean "I want my files as they were before I ran the initial git stash" : go back to the commit you were in before you called git checkout other-branch, and reapply the stash

# clean your worktree :
git stash

# go back to the previous branch :
git checkout the/active/branch/before/other-branch

# apply the stash :
git stash pop

You can use git stash apply instead of git stash pop if you want to "apply the stash" several times.

If you mean : "I want my files as they were before I ran git stash pop", just re-stash the content :

git stash
LeGEC
  • 46,477
  • 5
  • 57
  • 104