# Undo a git stash clear

5 messages from 2008-12-16 to 2008-12-16. Participants: Alexander Gladysh, Johannes Schindelin, Jeff King, Jonathan del Strother, Matthieu Moy.
Thread: https://gitlist.dev/t/16753

## Alexander Gladysh, 2008-12-16 12:07

Subject: Undo a git stash clear
Message-ID: <c6c947f60812160407l1b2593e1pde817f5cfb091d59@mail.gmail.com>
URL: https://gitlist.dev/e/c6c947f60812160407l1b2593e1pde817f5cfb091d59%40mail.gmail.com

```
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?

Alexander.

```

## Johannes Schindelin, 2008-12-16 12:10

Subject: Re: Undo a git stash clear
Message-ID: <alpine.DEB.1.00.0812161309370.14632@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0812161309370.14632%40racer
In-Reply-To: <c6c947f60812160407l1b2593e1pde817f5cfb091d59@mail.gmail.com>

```
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, 2008-12-16 12:12

Subject: Re: Undo a git stash clear
Message-ID: <20081216121245.GA8432@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20081216121245.GA8432%40coredump.intra.peff.net
In-Reply-To: <c6c947f60812160407l1b2593e1pde817f5cfb091d59@mail.gmail.com>

```
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, 2008-12-16 12:12

Subject: Re: Undo a git stash clear
Message-ID: <57518fd10812160412j1edc2ea0mff732825f1f6c4a2@mail.gmail.com>
URL: https://gitlist.dev/e/57518fd10812160412j1edc2ea0mff732825f1f6c4a2%40mail.gmail.com
In-Reply-To: <c6c947f60812160407l1b2593e1pde817f5cfb091d59@mail.gmail.com>

```
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

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, 2008-12-16 12:20

Subject: Re: Undo a git stash clear
Message-ID: <vpq1vw81fc8.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq1vw81fc8.fsf%40bauges.imag.fr
In-Reply-To: <57518fd10812160412j1edc2ea0mff732825f1f6c4a2@mail.gmail.com>

```
"Jonathan del Strother" <maillist@steelskies.com> writes:

> 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

```
