Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve a deleted stash that is not a stash-like commit

Tags:

git

I followed the directions here in order to recover a stash I deleted by mistake, but when I try to apply it, I get an error message:

boonie@elementary:~/akanbar-system$ git fsck --unreachable
Checking object directories: 100% (256/256), done.
Checking objects: 100% (702/702), done.
unreachable commit 0f34656bf920ac827702190de57459f77e8310ec
unreachable blob 3af4303a950ade7cca4c8c20b10404bc95b30605
unreachable commit f7142808a8b972f7ec259ca4a3c71c10a9549396
boonie@elementary:~/akanbar-system$ git stash apply 0f34656bf920ac827702190de57459f77e8310ec
'0f34656bf920ac827702190de57459f77e8310ec' is not a stash-like commit

I've tried searching for a solution but I can't find any. Please help!

Solution: Guys, I'm not sure how exactly this worked, but I applied the second unreachable commit instead of the first one (which was the one I wanted) and it restored everything back. They must have been connected somehow. Hopefully this helps someone in the future, and if not, someone who answers with another method below will also help!

like image 759
Jonathan Picazo Avatar asked Aug 23 '17 05:08

Jonathan Picazo


1 Answers

Recover lost stashed

  1. gitk --all $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )

  2. you can get it by reset or checkout to another branch.

    for Reset: git reset -- hard <hashCode>

    for Checkout: git branch <desire_branch_name> <hashCode>

like image 127
Archael Anie Avatar answered Nov 15 '22 09:11

Archael Anie