1

What part of this work flow was wrong: I tried to push, was told I couldn't because of changes not pulled. I tried to pull, was told I couldn't because of conflicts. I stashed all my changes and reset to the repo with git reset --hard. I unstashed my changes with git stash pop

The result is that my stash has been deleted but didn't get unstashed.

Alesi Rowland
  • 379
  • 2
  • 16
  • Related: https://stackoverflow.com/a/15286090/457268 – k0pernikus Feb 17 '20 at 16:50
  • 1
    Are you sure you did those commands in the order described? Your described behavior sounds like: `# git stash && git pop && git reset --hard` which would drop the stash basically removing your changes. I recommend using "git stash apply" over pop. (You can pick your stash number, and drop them explicitly.) – k0pernikus Feb 17 '20 at 16:54
  • Related: https://stackoverflow.com/q/89332/457268 – k0pernikus Feb 17 '20 at 16:54
  • This is what I thought! sadly I did it in this order and have lost a days worth of work. – Alesi Rowland Feb 17 '20 at 17:01
  • The above linked question may give you hints on how to recover a dropped stash. If that doesn't work: Depending on your IDE you may have access to a local history or depending on your OS, you may have a time machine to restore your work. – k0pernikus Feb 17 '20 at 17:10
  • @AlesiRowland : do you confirm that `git stash list` does not list the stash you expect ? – LeGEC Feb 17 '20 at 17:11

1 Answers1

1

You most likely did the commands out of order.

You intended to do:

git stash && git pull && git stash pop && git add {your-files} && git commit -m "your message" && git push

yet you most likely ended up doing:

# git stash && git pop && git reset --hard

Since git pop is basically a shortcut for git apply stash@{0} && git drop stash@{0} you applied your changes, and then deleted the applied stash. By resetting the repo via # git reset --hard you deleted your work.

I recommend using git stash apply over drop. You can have basically unlimmited amount of stash and browse them repeatedly, apply them, and delete them whenever you like.

You may be able to recover your dropped git stash or restor

k0pernikus
  • 60,309
  • 67
  • 216
  • 347
  • Okay, in short is the way I described in the question the right way anyway? – Alesi Rowland Feb 17 '20 at 17:31
  • @AlesiRowland I don't really understand why you saw the need for a `# git reset --hard` as that basically nukes all you local changes. I rarely use that one. – k0pernikus Feb 18 '20 at 17:19