# Implicit stashes

8 messages from 2010-06-30 to 2010-06-30. Participants: John Tapsell, Joshua Jensen, Jonathan Nieder, Sverre Rabbelier, Will Palmer, Alex.
Thread: https://gitlist.dev/t/24239

## John Tapsell, 2010-06-30 02:48

Subject: Implicit stashes
Message-ID: <AANLkTilTaQP6qARY1A495vm9HAvLVX_lqIQd1l3WIv7a@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTilTaQP6qARY1A495vm9HAvLVX_lqIQd1l3WIv7a%40mail.gmail.com

```
Hi,

  I was thinking that it would be nice if everything was undoable in
git.  Currently there are some easily typed by irreversible commands
that I keep seeing people doing.

For example:

$ git checkout folder

Now all changes that you just worked on are deleted, with no way of recovering.

$ git reset --hard

I know this seems very explicit to delete changes, but I myself have
done this and accidentally lost changes.  For example, I write a unit
test and don't commit it in on purpose because I know that it
currently fails and I want to test it against older versions.  I
carefully git checkout older versions to find if the unit test fails,
then in stupidity reset back to origin/master ..


  Anyway, I think a nice solution is to have a separate stash for
implicit stashes.  Then irreversible commands would simply stash
before making the changes.
  It would also be nice to add a 'git undo' which just undoes whatever
the last operation was - i.e  unstash or reset to an earlier HEAD@{1}

John

```

## Joshua Jensen, 2010-06-30 02:56

Subject: Re: Implicit stashes
Message-ID: <4C2AB260.8020108@workspacewhiz.com>
URL: https://gitlist.dev/e/4C2AB260.8020108%40workspacewhiz.com
In-Reply-To: <AANLkTilTaQP6qARY1A495vm9HAvLVX_lqIQd1l3WIv7a@mail.gmail.com>

```
  ----- Original Message -----
From: John Tapsell
Date: 6/29/2010 8:48 PM
>    I was thinking that it would be nice if everything was undoable in
> git.  Currently there are some easily typed by irreversible commands
> that I keep seeing people doing.
>
> For example:
>
> $ git checkout folder
>
> Now all changes that you just worked on are deleted, with no way of recovering.
>
> $ git reset --hard
>
> I know this seems very explicit to delete changes, but I myself have
> done this and accidentally lost changes.  For example, I write a unit
> test and don't commit it in on purpose because I know that it
> currently fails and I want to test it against older versions.  I
> carefully git checkout older versions to find if the unit test fails,
> then in stupidity reset back to origin/master ..
>    Anyway, I think a nice solution is to have a separate stash for
> implicit stashes.  Then irreversible commands would simply stash
> before making the changes.
>    It would also be nice to add a 'git undo' which just undoes whatever
> the last operation was - i.e  unstash or reset to an earlier HEAD@{1}
See this thread: http://kerneltrap.org/mailarchive/git/2009/5/20/2915

Josh

```

## John Tapsell, 2010-06-30 03:05

Subject: Re: Implicit stashes
Message-ID: <AANLkTimOTBzN7lnniImy2eqoBh775X9NbzIwcetS1GHh@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimOTBzN7lnniImy2eqoBh775X9NbzIwcetS1GHh%40mail.gmail.com
In-Reply-To: <4C2AB260.8020108@workspacewhiz.com>

```
On 30 June 2010 11:56, Joshua Jensen <jjensen@workspacewhiz.com> wrote:
>  ----- Original Message -----
> From: John Tapsell
> Date: 6/29/2010 8:48 PM
>>
>>   I was thinking that it would be nice if everything was undoable in
>> git.  Currently there are some easily typed by irreversible commands
>> that I keep seeing people doing.
>> <snip>
> See this thread: http://kerneltrap.org/mailarchive/git/2009/5/20/2915

Doh.

It seems that everyone agreed in principle, but that the details are
tricky and it needs someone to actually do it.

I can't do it myself, but I'll give $50 to someone to get this going
and do this :)  (I know that is an insultingly low amount, sorry)

John

```

## Jonathan Nieder, 2010-06-30 05:13

Subject: Dangers of reset --hard (Re: Implicit stashes)
Message-ID: <20100630051326.GA17497@burratino>
URL: https://gitlist.dev/e/20100630051326.GA17497%40burratino
In-Reply-To: <AANLkTilTaQP6qARY1A495vm9HAvLVX_lqIQd1l3WIv7a@mail.gmail.com>

```
John Tapsell wrote:

> $ git reset --hard
>
> I know this seems very explicit to delete changes, but I myself have
> done this and accidentally lost changes.  For example, I write a unit
> test and don't commit it in on purpose because I know that it
> currently fails and I want to test it against older versions.  I
> carefully git checkout older versions to find if the unit test fails,
> then in stupidity reset back to origin/master ..

Aside: I assume you already know about it, but still I cannot help but
take the opportunity to advertise ‘git reset --keep’.  I was added
fairly recently (1.7.1 rc0) and I find myself annoyed when on machines
without it because of almost exactly this use case.

Stephan and Christian: thanks for writing it.

```

## Sverre Rabbelier, 2010-06-30 05:57

Subject: Re: Implicit stashes
Message-ID: <AANLkTimIJcOe3fufZx83LxI8ZSDP8cCOj1BEPPbUy7Ol@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimIJcOe3fufZx83LxI8ZSDP8cCOj1BEPPbUy7Ol%40mail.gmail.com
In-Reply-To: <AANLkTimOTBzN7lnniImy2eqoBh775X9NbzIwcetS1GHh@mail.gmail.com>

```
Heya,

On Wed, Jun 30, 2010 at 05:05, John Tapsell <johnflux@gmail.com> wrote:
> I can't do it myself, but I'll give $50 to someone to get this going
> and do this :)  (I know that is an insultingly low amount, sorry)

Hehe, I'll match your $50 and raise you a beer ;). Isn't there some
relevant site where people can pledge for stuff like this? Either way,
I doubt for most lack of financial stimulation is what's stopping them
from implementing this, but rather lack of time which cannot really be
compensated financially.

-- 
Cheers,

Sverre Rabbelier

```

## Will Palmer, 2010-06-30 08:19

Subject: Re: Dangers of reset --hard (Re: Implicit stashes)
Message-ID: <1277885972.2498.25.camel@wpalmer.simply-domain>
URL: https://gitlist.dev/e/1277885972.2498.25.camel%40wpalmer.simply-domain
In-Reply-To: <20100630051326.GA17497@burratino>

```
On Wed, 2010-06-30 at 00:13 -0500, Jonathan Nieder wrote:
> John Tapsell wrote:
> 
> > $ git reset --hard
> >
> > I know this seems very explicit to delete changes, but I myself have
> > done this and accidentally lost changes.  For example, I write a unit
> > test and don't commit it in on purpose because I know that it
> > currently fails and I want to test it against older versions.  I
> > carefully git checkout older versions to find if the unit test fails,
> > then in stupidity reset back to origin/master ..
> 
> Aside: I assume you already know about it, but still I cannot help but
> take the opportunity to advertise ‘git reset --keep’.  I was added
> fairly recently (1.7.1 rc0) and I find myself annoyed when on machines
> without it because of almost exactly this use case.

I tend to want "do a git reset --hard, but fail if anything would be
lost". The use-case here is that when I reset --hard, I want a
completely clean copy- but I don't want to accidentally lose anything.

This can probably be achieved with something like:
git diff-files --quiet &&
  git diff-index --quiet HEAD &&
  git diff-index --cached --quiet HEAD ||
  git reset --hard "$@"

I've got a half-done patch sitting at home which adds -g, --gentle to
"git reset", which is intended to do exactly that- but my git-fu is not
very strong on the C end of things, so for the foreseeable future it
will remain an idea without a working implementation.

```

## Alex, 2010-06-30 11:27

Subject: Re: Implicit stashes
Message-ID: <loom.20100630T132533-495@post.gmane.org>
URL: https://gitlist.dev/e/loom.20100630T132533-495%40post.gmane.org
In-Reply-To: <AANLkTimIJcOe3fufZx83LxI8ZSDP8cCOj1BEPPbUy7Ol@mail.gmail.com>

```
Sverre Rabbelier <srabbelier <at> gmail.com> writes:


> Hehe, I'll match your $50 and raise you a beer ;). Isn't there some
> relevant site where people can pledge for stuff like this? Either way,
> I doubt for most lack of financial stimulation is what's stopping them
> from implementing this, but rather lack of time which cannot really be
> compensated financially.

There are a few:
http://fossfactory.org
http://nextsprocket.com
http://www.opensourcexperts.com/

Alex

```

## Jonathan Nieder, 2010-06-30 16:12

Subject: Re: Dangers of reset --hard (Re: Implicit stashes)
Message-ID: <20100630161217.GE18813@burratino>
URL: https://gitlist.dev/e/20100630161217.GE18813%40burratino
In-Reply-To: <1277885972.2498.25.camel@wpalmer.simply-domain>

```
Will Palmer wrote:

> I tend to want "do a git reset --hard, but fail if anything would be
> lost".

At the risk of being redundant: try git reset --keep.  If it succeeds,
you can use git diff --cached HEAD and git diff to check how close it
was to being equivalent to a hard reset.

> The use-case here is that when I reset --hard, I want a
> completely clean copy- but I don't want to accidentally lose anything.

There is one case when I truly want a completely clean copy (including
no untracked files): when I am testing and a bit paranoid.  For that,
I do something like the following:

 ; mkdir /tmp/test-dir
 ; git archive HEAD | (cd /tmp/test-dir && tar -xf -)
 ; cd /tmp/test-dir

and work from there.  I would not be surprised if the needs of your
case are different, though.

```
