I still save changes to a file if I switch/merge while having a bigger changeset as I use PHPStorm and it caused me a semi heart attack at least 3 times with the “unstashing failed“ error (that also removed it from the stash at the same time)
The best thing about Jetbrains IDEs is local file history - so you dont have to rely on git - you can still see file history and directory history to restore commits and deleted files. Saved me many times.
Thanks I didn't even know that was there, this will help me. It looks like its files only, not directories which is important to get accidentally deleted files.
Local history is great and I dont understand why it's separate from the undo stack, which is limited in size (by default?). Actually, both could be integrated with SCM as fine grained autocommits + eventual squash on manual checkpoint / push.
The other option here is to do a "WIP" (work in progress) commit. Which you can undo (moving the files back into the staging area) with `git reset HEAD^` once you switch back to the branch. Annoying that this is necessary - it would be great if git stash was as robust - but this won't lose your work.
You can also use `git stash apply` (which doesn't pop the stash), followed by maybe merging, and finally a `git stash drop`.
You can also use the git reflog to get the recently dropped stash commit's sha, and then check out the files that you miss.
If a change has ever been committed or stashed (which is basically also committing, just not on a branch), it can always be recovered, at least until garbage collection is run - check out the reflog. Of course, if it hasn't been, then you can lose it.
Yeah, working out which stash contains your work can be quite tricky though! As they are not named by default.
You can add a tag to the change you want to keep. Whatever you do, you can recover it (git reset --hard tag). Once you are done, remove the tag. Otherwise, there is the reflog, like mentioned in a sister comment.