threads / discuss / 24239

Implicit stashes

Subject: Implicit stashes

## tl;dr

8 messages between Jun 30, 2010 and Jun 30, 2010.

replies: 7people: 6as markdown or json

John Tapsell· Jun 30, 2010, 02:48 UTC · lore
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· Jun 30, 2010, 02:56 UTC · re: John Tapsell · lore

Re: Implicit stashes

  ----- Original Message -----
From: John Tapsell
Date: 6/29/2010 8:48 PM
Show 23 quoted lines
>    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· Jun 30, 2010, 03:05 UTC · re: Joshua Jensen · lore

Re: Implicit stashes

On 30 June 2010 11:56, Joshua Jensen <jjensen@workspacewhiz.com> wrote:
Show 9 quoted lines
>  ----- 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
Sverre Rabbelier· Jun 30, 2010, 05:57 UTC · re: John Tapsell · lore

Re: Implicit stashes

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
Alex· Jun 30, 2010, 11:27 UTC · re: Sverre Rabbelier · lore

Re: Implicit stashes

Sverre Rabbelier <srabbelier <at> gmail.com> writes:
Show 5 quoted lines
> 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· Jun 30, 2010, 05:13 UTC · re: John Tapsell · lore

Dangers of reset --hard (Re: Implicit stashes)

John Tapsell wrote:
Show 8 quoted lines
> $ 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.
Will Palmer· Jun 30, 2010, 08:19 UTC · re: Jonathan Nieder · lore

Re: Dangers of reset --hard (Re: Implicit stashes)

On Wed, 2010-06-30 at 00:13 -0500, Jonathan Nieder wrote:
Show 15 quoted lines
> 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.

Jonathan Nieder· Jun 30, 2010, 16:12 UTC · re: Will Palmer · lore

Re: Dangers of reset --hard (Re: Implicit stashes)

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.

← back to recent threads