I frequently use “git stash” and “git stash pop” to save and restore changes in my working tree. This is what I did and my previous uncommitted changes now are gone.
git stash -u
git checkout master
git pull --rebase
git checkout dev
git merge --no-ff master
10 files changed, 1000 insertions(+), 2000 deletions(-)
git stash pop
CONFLICT (content): Merge conflict in file.ext
Then I thought I could revert the merge, and I did:
git reset --hard origin/master
git reset --hard origin/master
Now I don’t see any of my previous stashed uncommitted changes anywhere in file.ext, only the merged code. How can I bring back all the changes that I originally stashed?
When you
popoff thestash, it removes it from thestashas well. So the stashed changes were dumped back into your working directory. Then, when youreset, you reverted those same changes.git reset --hardis one of the few dangerous “you-could-totally-lose-work-here” commands. This explains the different aspects ofresetreally well.To sum up, they aren’t in the
stashanymore, and youresetthe working directory. So they were most likely lost to the ether of bits and bytes. Though since those changes were once stashed, you may be able to find the commit withgit fsck --lost-found.