git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
* Can I remove multiple stashed states at a time?
@ 2017-10-13  2:58 小川恭史
  2017-10-13 17:35 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: 小川恭史 @ 2017-10-13  2:58 UTC (permalink / raw)
  To: git

I want to remove multiple stashed states at a time.

But "git stash drop <stash>" removes only one stashed state at a time
and "git stash clear" remove all.

Can I do that?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Can I remove multiple stashed states at a time?
  2017-10-13  2:58 Can I remove multiple stashed states at a time? 小川恭史
@ 2017-10-13 17:35 ` Jeff King
  2017-10-14 15:01   ` Kevin Daudt
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2017-10-13 17:35 UTC (permalink / raw)
  To: 小川恭史; +Cc: git

On Fri, Oct 13, 2017 at 11:58:12AM +0900, 小川恭史 wrote:

> I want to remove multiple stashed states at a time.
> 
> But "git stash drop <stash>" removes only one stashed state at a time
> and "git stash clear" remove all.
> 
> Can I do that?

There isn't a way to do it through "git stash", I don't think. The stash
feature is backed by a reflog, and the underlying machinery is capable
of it. E.g.:

  git reflog delete --updateref --rewrite refs/stash@{1} refs/stash@{2} refs/stash@{3}

works. But that's getting a bit more familiar with the innards of stash
than users should be (both because they shouldn't need to, and because
the underlying storage may be subject to change).

Probably "git stash drop" should learn to take multiple stash arguments
and pass them all along to "reflog delete".

You can also just do:

  for i in 1 2 3; do
     git stash drop $i
  done

of course. It's less efficient than a single invocation (since it has to
rewrite the whole reflog each time), but unless you have thousands of
stashes, I doubt the difference is all that noticeable.

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Can I remove multiple stashed states at a time?
  2017-10-13 17:35 ` Jeff King
@ 2017-10-14 15:01   ` Kevin Daudt
  2017-10-14 18:05     ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Daudt @ 2017-10-14 15:01 UTC (permalink / raw)
  To: Jeff King; +Cc: 小川恭史, git

On Fri, Oct 13, 2017 at 01:35:22PM -0400, Jeff King wrote:
> On Fri, Oct 13, 2017 at 11:58:12AM +0900, 小川恭史 wrote:
> 
> You can also just do:
> 
>   for i in 1 2 3; do
>      git stash drop $i
>   done
> 

Doesn't stash 2 become stash 1 after the first drop, and the same for 3,
resulting in dropping stash 1, 3 and 5?

So something like

  for i in 3 2 1; do
      git stash drop $i;
  done

Or leave $i out altogether.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Can I remove multiple stashed states at a time?
  2017-10-14 15:01   ` Kevin Daudt
@ 2017-10-14 18:05     ` Jeff King
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2017-10-14 18:05 UTC (permalink / raw)
  To: Kevin Daudt; +Cc: 小川恭史, git

On Sat, Oct 14, 2017 at 05:01:23PM +0200, Kevin Daudt wrote:

> On Fri, Oct 13, 2017 at 01:35:22PM -0400, Jeff King wrote:
> > On Fri, Oct 13, 2017 at 11:58:12AM +0900, 小川恭史 wrote:
> > 
> > You can also just do:
> > 
> >   for i in 1 2 3; do
> >      git stash drop $i
> >   done
> > 
> 
> Doesn't stash 2 become stash 1 after the first drop, and the same for 3,
> resulting in dropping stash 1, 3 and 5?
> 
> So something like
> 
>   for i in 3 2 1; do
>       git stash drop $i;
>   done
> 
> Or leave $i out altogether.

Oops, you're right.

For that matter, I didn't double check that a single "reflog delete"
handles this case correctly. That should be easy to test, though:

  git init
  echo base >file
  git add file
  git commit -m base

  for i in $(seq 10); do
    echo $i >file
    git stash push -m $i
  done

  git reflog delete --updateref --rewrite refs/stash@{1} refs/stash@{2} refs/stash@{3}

That seems to leave:

  $ git stash list
  stash@{0}: On master: 10
  stash@{1}: On master: 8
  stash@{2}: On master: 6
  stash@{3}: On master: 4
  stash@{4}: On master: 3
  stash@{5}: On master: 2
  stash@{6}: On master: 1

which is not what we wanted (I'd guess also that it rewrites the reflog
3 times, negating any efficiency I claimed earlier).

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-13  2:58 Can I remove multiple stashed states at a time? 小川恭史
2017-10-13 17:35 ` Jeff King
2017-10-14 15:01   ` Kevin Daudt
2017-10-14 18:05     ` Jeff King

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox