[FIXED] Git changes deleted after stashing with no stash to restore

Issue

I was about ready to push my branch and create a pull request when I noticed the branch display in visual studio said ‘Unknown Repository’

For some reason I decided to stash my changes. In visual studio I clicked ‘Stash All (–include-untracked)’

After this my repository showed correctly and the branch showed correctly. But all my changes were gone and there was no stash to restore.

Is there any way I can get my changes back?

Solution

Good news.
I managed to find a list of the stashes in .git/logs/refs/stash

This contained a list of my previous stashes including the last stash that caused all the troubles.

This line has 2 hashes. The first hash was the same as one of the hashes of a stash above. So I took the 2nd hash and ran this command in the package manager console of visual studio:

git stash apply {StashHash}

This applied the changes and I could then commit and push to the remote branch.

I hope this helps someone in future.

Answered By – TheEvilMetal

Answer Checked By – Marie Seifert (FixeMe Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *