# My stash wants to delete all my files

6 messages from 2007-09-24 to 2007-09-25. Participants: Jonathan del Strother, Junio C Hamano, Johannes Schindelin.
Thread: https://gitlist.dev/t/9996

## Jonathan del Strother, 2007-09-24 13:12

Subject: My stash wants to delete all my files
Message-ID: <5A9D6E3B-7B0E-4414-9AFB-C1C8B2EE6A9D@steelskies.com>
URL: https://gitlist.dev/e/5A9D6E3B-7B0E-4414-9AFB-C1C8B2EE6A9D%40steelskies.com

```
Heya,
I've run into a problem with git stash.  I suspect that I've already  
lost the work that I tried to stash, but would like to know where I  
went wrong.

I had some work in progress, wanted to check something from my last  
commit, and typed "git stash".  I forgot to "git stash apply"  
immediately afterward, and carried on doing some more work related to  
the stashed code.  I realized that I'd got a stash that I wanted to  
apply, and tried to restore it.
While trying to restore it, I typed "git stash --apply", which  
actually created a new stash named "--apply".  Ooops.  Anyway, the  
real problem is :

$ git stash list
stash@{0}: On master: --apply
stash@{1}: WIP on master: 09e3c30... Better handling of cell sizes in  
the grid

$ git stash show stash@{1}
  .gitignore                            |    3 -
  AppController.h                       |   10 -
  AppController.m                       |   30 -
  English.lproj/InfoPlist.strings       |  Bin 202 -> 0 bytes
  English.lproj/MainMenu.xib            | 2560  
---------------------------------
  GLScene.h                             |   21 -
  GLScene.m                             |  287 ----
  Info.plist                            |   28 -
  LayoutManager.h                       |   19 -
  LayoutManager.m                       |  118 --
  OpenGLTests.xcodeproj/project.pbxproj |  323 -----
  OpenGLTests_Prefix.pch                |   10 -
  TheWall.h                             |   28 -
  TheWall.m                             |   99 --
  UserImage.h                           |   17 -
  UserImage.m                           |  111 --
  Utilities.h                           |   38 -
  Utilities.m                           |   89 --
  main.m                                |   14 -
  19 files changed, 0 insertions(+), 3805 deletions(-)


Hmm.  Looks like it's trying to delete all of my versioned files.   
"git stash apply stash@{1}" confirms this.   Obviously that's not what  
I tried to stash - my WIP when I stashed was a few additions, a couple  
of new unversioned files, and moving a few lines of code from one file  
to another.

Any ideas what happened there?  I can't seem to reproduce the problem  
in a test repository.

Cheers,
Jon

```

## Junio C Hamano, 2007-09-25 01:26

Subject: Re: My stash wants to delete all my files
Message-ID: <7vabrb8rin.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vabrb8rin.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <5A9D6E3B-7B0E-4414-9AFB-C1C8B2EE6A9D@steelskies.com>

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

> $ git stash list
> stash@{0}: On master: --apply
> stash@{1}: WIP on master: 09e3c30... Better handling of cell sizes in
> the grid
>
> $ git stash show stash@{1}
>  ...
>  19 files changed, 0 insertions(+), 3805 deletions(-)
>
> Hmm.  Looks like it's trying to delete all of my versioned files.
> "git stash apply stash@{1}" confirms this.   Obviously that's not what
> I tried to stash - my WIP when I stashed was a few additions, a couple
> of new unversioned files, and moving a few lines of code from one file
> to another.
>
> Any ideas what happened there?  I can't seem to reproduce the problem
> in a test repository.

There are two possibilities that I can think of offhand, neither
of them is about git-stash but about the state you ran stash
from.

Whenever anybody wonders where inadvertent reverting changes
come from, two most likely reasons are incorrect push into the
current branch's tip initiated from elsewhere, or incorrect
fetch into the current branch's tip initiated from the
repository.

If your work repository is foo, and if you are working on
'master' branch, you could

	$ cd ../bar ; git push ../foo master:master

to push from elsewhere to update the tip of the checked out
branch.  This makes the index and the work tree that was based
on the old commit in foo repository totally out of sync with
respect to the HEAD (which you are replacing), and committing
that state would revert the change the above push made.

You can do the same by doing something equally silly and
destructive by:

	$ git fetch --update-head-ok ../bar master:master

After these operations that could make your index and work
tree state to include reverts, if you "stash", the stash will
record that the reverting was what you wanted to do.

I am not saying this is the only possible explanation though.
You can try:

	git ls-tree stash@{1}
        git rev-parse stash@{1}^1
        git diff stash@{1}^1 stash@{1}^2

The stash entry itself is the state of the work tree, its first
parent (i.e. ^1) is the commit your stash was originally based
on, and its second parent (i.e. ^2) is what was recorded in the
index.  Is the output from the first one empty?  Does the second
command show you that you were on the commit you thought you were
on?  Does the third command show you what you thought you have
told "git add" to put in the index just before you made the
stash?

```

## Jonathan del Strother, 2007-09-25 09:27

Subject: Re: My stash wants to delete all my files
Message-ID: <DCBF8566-9B43-4EFA-A8B2-2EAB516C273F@steelskies.com>
URL: https://gitlist.dev/e/DCBF8566-9B43-4EFA-A8B2-2EAB516C273F%40steelskies.com
In-Reply-To: <7vabrb8rin.fsf@gitster.siamese.dyndns.org>

```

On 25 Sep 2007, at 02:26, Junio C Hamano wrote:

> Jonathan del Strother <maillist@steelskies.com> writes:
>
>> $ git stash list
>> stash@{0}: On master: --apply
>> stash@{1}: WIP on master: 09e3c30... Better handling of cell sizes in
>> the grid
>>
>> $ git stash show stash@{1}
>> ...
>> 19 files changed, 0 insertions(+), 3805 deletions(-)
>>
>> Hmm.  Looks like it's trying to delete all of my versioned files.
>> "git stash apply stash@{1}" confirms this.   Obviously that's not  
>> what
>> I tried to stash - my WIP when I stashed was a few additions, a  
>> couple
>> of new unversioned files, and moving a few lines of code from one  
>> file
>> to another.
>>
>> Any ideas what happened there?  I can't seem to reproduce the problem
>> in a test repository.
>
> ...
> Whenever anybody wonders where inadvertent reverting changes
> come from, two most likely reasons are incorrect push into the
> current branch's tip initiated from elsewhere, or incorrect
> fetch into the current branch's tip initiated from the
> repository.

I'm working on a single isolated repository, so haven't pushed,  
pulled, fetched, or anything.


> 	git ls-tree stash@{1}
>        git rev-parse stash@{1}^1
>        git diff stash@{1}^1 stash@{1}^2
>

ls-tree is empty.  rev-parse confirms I was on the right revision when  
I stashed, and the diff shows everything being deleted.


> Does the third command show you what you thought you have
> told "git add" to put in the index just before you made the
> stash?

I don't think I git-added anything - just made changes to the working  
copy.  (It *does* stash those, right??)


I'm at a loss to explain what happened here...

```

## Johannes Schindelin, 2007-09-25 09:56

Subject: Re: My stash wants to delete all my files
Message-ID: <Pine.LNX.4.64.0709251054440.28395@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0709251054440.28395%40racer.site
In-Reply-To: <DCBF8566-9B43-4EFA-A8B2-2EAB516C273F@steelskies.com>

```
Hi,

On Tue, 25 Sep 2007, Jonathan del Strother wrote:

> I don't think I git-added anything - just made changes to the working 
> copy. (It *does* stash those, right??)

Stash does not care about things that are not tracked, so no, it does not 
stash those.  Imagine a stash saving all those .o, .a and .so files... 
Insanity!

Ciao,
Dscho

```

## Jonathan del Strother, 2007-09-25 10:22

Subject: Re: My stash wants to delete all my files
Message-ID: <0F9BDBCD-06AA-4AB1-9DDA-9C98E8796AA1@steelskies.com>
URL: https://gitlist.dev/e/0F9BDBCD-06AA-4AB1-9DDA-9C98E8796AA1%40steelskies.com
In-Reply-To: <Pine.LNX.4.64.0709251054440.28395@racer.site>

```

On 25 Sep 2007, at 10:56, Johannes Schindelin wrote:

> Hi,
>
> On Tue, 25 Sep 2007, Jonathan del Strother wrote:
>
>> I don't think I git-added anything - just made changes to the working
>> copy. (It *does* stash those, right??)
>
> Stash does not care about things that are not tracked, so no, it  
> does not
> stash those.  Imagine a stash saving all those .o, .a and .so files...
> Insanity!


Mm, ok - fair point.  I was actually thinking of files that are  
already tracked, but haven't been added to the staging area with git  
add.

```

## Johannes Schindelin, 2007-09-25 10:41

Subject: Re: My stash wants to delete all my files
Message-ID: <Pine.LNX.4.64.0709251139480.28395@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0709251139480.28395%40racer.site
In-Reply-To: <0F9BDBCD-06AA-4AB1-9DDA-9C98E8796AA1@steelskies.com>

```
Hi,

On Tue, 25 Sep 2007, Jonathan del Strother wrote:

> On 25 Sep 2007, at 10:56, Johannes Schindelin wrote:
> 
> > On Tue, 25 Sep 2007, Jonathan del Strother wrote:
> > 
> > > I don't think I git-added anything - just made changes to the 
> > > working copy. (It *does* stash those, right??)
> > 
> > Stash does not care about things that are not tracked, so no, it does 
> > not stash those.  Imagine a stash saving all those .o, .a and .so 
> > files... Insanity!
> 
> 
> Mm, ok - fair point.  I was actually thinking of files that are already 
> tracked, but haven't been added to the staging area with git add.

Ah.  I read your statement as "I don't think I git-added anything, ever".

So this is what stash is supposed to do:

- save the differences between the HEAD and the index

- save the differences between the HEAD and the working tree

- reset the index and the working tree to the state of the HEAD

So indeed, I am as puzzled as you are.  Maybe it was your initial commit?

Ciao,
Dscho

```
