threads / discuss / 16753

Undo a git stash clear

Subject: Undo a git stash clear

## tl;dr

5 messages between Dec 16, 2008 and Dec 16, 2008.

replies: 4people: 5as markdown or json

Johannes Schindelin· Dec 16, 2008, 12:10 UTC · re: Alexander Gladysh · lore

Re: Undo a git stash clear

Hi,
On Tue, 16 Dec 2008, Alexander Gladysh wrote:
> I've stashed some valuable changes and then I accidentally did git stash 
> clear. (Yes, today is not my day).
> 
> Is it possible to restore stashed changes?
You might find them with "git fsck --lost-found".

Hth, Dscho

Jeff King· Dec 16, 2008, 12:12 UTC · re: Alexander Gladysh · lore

Re: Undo a git stash clear

On Tue, Dec 16, 2008 at 03:07:28PM +0300, Alexander Gladysh wrote:
> I've stashed some valuable changes and then I accidentally did git
> stash clear. (Yes, today is not my day).
> 
> Is it possible to restore stashed changes?

Try git-fsck; it should report some dangling commits (i.e., commits that are in the object db but aren't reachable by any refs). Then you can either pull the changes out directly (try git cherry-pick -m1 $sha1) or you can even restore it as a stash (git update-ref -m oops refs/stash $sha1).

-Peff
Jonathan del Strother· Dec 16, 2008, 12:12 UTC · re: Alexander Gladysh · lore

Re: Undo a git stash clear

On Tue, Dec 16, 2008 at 12:07 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
Show 6 quoted lines
> Hi, list!
>
> I've stashed some valuable changes and then I accidentally did git
> stash clear. (Yes, today is not my day).
>
> Is it possible to restore stashed changes?

I ran into this exact problem on Friday. Some helpful person on IRC suggested using

git fsck | grep commit | cut -d' ' -f3 | while read hash; do git rev-parse --verify --quiet $hash^2 && echo $hash; done | xargs git show

Which will show a huge list of lost changes. Once you find the change you're interested in, you can cherry-pick its sha1.

Matthieu Moy· Dec 16, 2008, 12:20 UTC · re: Jonathan del Strother · lore

Re: Undo a git stash clear

"Jonathan del Strother" <maillist@steelskies.com> writes:
Show 10 quoted lines
> On Tue, Dec 16, 2008 at 12:07 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
>> Hi, list!
>>
>> I've stashed some valuable changes and then I accidentally did git
>> stash clear. (Yes, today is not my day).
>>
>> Is it possible to restore stashed changes?
>
> I ran into this exact problem on Friday.  Some helpful person on IRC
> suggested using

(and the obvious advice before anything else : don't "git gc", don't "git prune", and if possible back-up the repository before anything else)

-- 
Matthieu

← back to recent threads