lost git stash changes

Something similar happened to me. In short, check to make sure you didn't accidentally push the new files to the other branch.

Here's what happened to me: I stashed my stuff, switched from 'dev' to 'master' to do a hotfix quick. When I pushed my hotfix to master, I didn't notice that I also added my new files that were meant for dev to the master branch--I too assumed stash included those files.


Stashes should be viewable via

git stash list

or

gitk --all

also, git stash does not stash untracked files. If you did this and subsequently did a git checkout --force of another branch to overwrite untracked files with tracked ones in another branch, you have lost that content. The recommended way to stash is with

git stash -u

This will prevent losses of this type.


We also faced the same issue. So, here is how we recovered the lost changes:

  1. Go back to branch B.

    git checkout B

  2. Use git reflog option to mange reflog information.

    git reflog --all

    Output:

    f332d5c refs/stash@{0}: WIP on B: aa1d0c1 xyz commit message

  3. Now, switch to branch A using git checkout A

  4. Finally, to recover your lost changes.

    git stash apply f332d5c

Tags:

Git

Git Stash