Not quite sure what\'s happened, but git stash seems to be in a bad place.
% git stash list
stash@{0}: filter-branch: rewrite
stash@{1}: filter-branch: rewri
I think filter-branch
has broken your stashes. If the argument to git stash
does not sufficiently resemble a stash bag, you get that not a stash reference
complaint.
Note that git show stashref
uses plain old git show
, which does not require that a commit given as an argument resemble a stash. If git stash show
fails the same way as the other git stash
commands, or if manual examination of the stash in question shows that it's no longer a two- or three-parent merge commit, then this is in fact the case.
It was likely the --prune-empty
that did it here. If you had not add
ed anything at the time of the stash, the index commits would be empty. In general it's probably wiser to avoid filtering stash refs.
You can try two different approaches:
refs/original/
(where filter-branch
left them) and/or reflogs; use those to rebuild refs/stash
and/or the stash reflogs, or use them directly and then clobber the stash ref and its reflog.git show
command you've already run.(For a bit more on stash and stash bags, including the three-parent form used with --all
or --untracked
, see How to recover from “git stash save --all”?.)
Assuming you have gotten your contents back and wish to wipe out the stash
reference entirely, this will do it. Note that this is the "nuke it from orbit" option—don't do it until you're sure you're ready:
git update-ref -d refs/stash
You don’t have to nuke all of your stashes. You can delete just the broken ones manually using git reflog
. In your case:
git reflog delete --rewrite stash@{1}
git reflog delete --rewrite stash@{0}
(I put these in reverse order here because every deletion decreases the numbering of the following entries. In practice, don’t bother doing the math mentally, just do git stash list
after every deletion to get an updated list and pick another remaining broken entry from that.)
all above answers don't work for me, the below command work, it can delete one stash which you want. I hope it will work for you.
```
git stash list
//--- apply target stash
git stash apply refs/stash@{n}
//---- delete target stash
git stash drop --index n
// or
git stash drop refs/stash@{n}
```