git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Can I remove multiple stashed states at a time?

From
Jeff King <peff@peff.net>
Date
Oct 13, 2017, 17:35 UTC
Message-ID
<20171013173522.vprwjwprhnoiyajy@sigill.intra.peff.net>
In-Reply-To
<CAC2JkrLm3QCNW1t-Yju-sA=9Tbv8hH1AHZUEDux8kSG9mkG5wg@mail.gmail.com>
On Fri, Oct 13, 2017 at 11:58:12AM +0900, 小川恭史 wrote:
Show 6 quoted lines
> 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
Previous: 小川恭史Next: Kevin Daudt
Message 2 of 4 in “Can I remove multiple stashed states at a time?”
  1. 小川恭史Oct 13, 2017
  2. Jeff KingOct 13, 2017
  3. Kevin DaudtOct 14, 2017
  4. Jeff KingOct 14, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.