Question

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?

Was it helpful?

Solution

When you pop off the stash, it removes it from the stash as well. So the stashed changes were dumped back into your working directory. Then, when you reset, you reverted those same changes.

git reset --hard is one of the few dangerous "you-could-totally-lose-work-here" commands. This explains the different aspects of reset really well.

To sum up, they aren't in the stash anymore, and you reset the 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 with git fsck --lost-found.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top