{"thread":{"id":"46962","subject":"Can I remove multiple stashed states at a time?","startedAt":"2017-10-13T02:58:18Z","lastAt":"2017-10-14T18:06:08Z","messageCount":4,"participants":["小川恭史","Jeff King","Kevin Daudt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"330331","messageId":"CAC2JkrLm3QCNW1t-Yju-sA=9Tbv8hH1AHZUEDux8kSG9mkG5wg@mail.gmail.com","threadId":"46962","inReplyTo":null,"subject":"Can I remove multiple stashed states at a time?","fromName":"小川恭史","fromEmail":"aiueogawa217@gmail.com","sentAt":"2017-10-13T02:58:12Z","receivedAt":"2017-10-13T02:58:18Z","isPatch":false,"sender":{"key":"aiueogawa217@gmail.com","avatar":null},"body":"I want to remove multiple stashed states at a time.\n\nBut \"git stash drop <stash>\" removes only one stashed state at a time\nand \"git stash clear\" remove all.\n\nCan I do that?\n"},{"id":"330375","messageId":"20171013173522.vprwjwprhnoiyajy@sigill.intra.peff.net","threadId":"46962","inReplyTo":"CAC2JkrLm3QCNW1t-Yju-sA=9Tbv8hH1AHZUEDux8kSG9mkG5wg@mail.gmail.com","subject":"Re: Can I remove multiple stashed states at a time?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-10-13T17:35:22Z","receivedAt":"2017-10-13T17:35:28Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Oct 13, 2017 at 11:58:12AM +0900, 小川恭史 wrote:\n\n> I want to remove multiple stashed states at a time.\n> \n> But \"git stash drop <stash>\" removes only one stashed state at a time\n> and \"git stash clear\" remove all.\n> \n> Can I do that?\n\nThere isn't a way to do it through \"git stash\", I don't think. The stash\nfeature is backed by a reflog, and the underlying machinery is capable\nof it. E.g.:\n\n  git reflog delete --updateref --rewrite refs/stash@{1} refs/stash@{2} refs/stash@{3}\n\nworks. But that's getting a bit more familiar with the innards of stash\nthan users should be (both because they shouldn't need to, and because\nthe underlying storage may be subject to change).\n\nProbably \"git stash drop\" should learn to take multiple stash arguments\nand pass them all along to \"reflog delete\".\n\nYou can also just do:\n\n  for i in 1 2 3; do\n     git stash drop $i\n  done\n\nof course. It's less efficient than a single invocation (since it has to\nrewrite the whole reflog each time), but unless you have thousands of\nstashes, I doubt the difference is all that noticeable.\n\n-Peff\n"},{"id":"330394","messageId":"20171014150123.GA28038@alpha.vpn.ikke.info","threadId":"46962","inReplyTo":"20171013173522.vprwjwprhnoiyajy@sigill.intra.peff.net","subject":"Re: Can I remove multiple stashed states at a time?","fromName":"Kevin Daudt","fromEmail":"me@ikke.info","sentAt":"2017-10-14T15:01:23Z","receivedAt":"2017-10-14T15:01:29Z","isPatch":false,"sender":{"key":"me@ikke.info","avatar":"https://avatars.githubusercontent.com/u/135698?v=4"},"body":"On Fri, Oct 13, 2017 at 01:35:22PM -0400, Jeff King wrote:\n> On Fri, Oct 13, 2017 at 11:58:12AM +0900, 小川恭史 wrote:\n> \n> You can also just do:\n> \n>   for i in 1 2 3; do\n>      git stash drop $i\n>   done\n> \n\nDoesn't stash 2 become stash 1 after the first drop, and the same for 3,\nresulting in dropping stash 1, 3 and 5?\n\nSo something like\n\n  for i in 3 2 1; do\n      git stash drop $i;\n  done\n\nOr leave $i out altogether.\n"},{"id":"330395","messageId":"20171014180549.q35km6t44pkpwzdh@sigill.intra.peff.net","threadId":"46962","inReplyTo":"20171014150123.GA28038@alpha.vpn.ikke.info","subject":"Re: Can I remove multiple stashed states at a time?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-10-14T18:05:50Z","receivedAt":"2017-10-14T18:06:08Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Oct 14, 2017 at 05:01:23PM +0200, Kevin Daudt wrote:\n\n> On Fri, Oct 13, 2017 at 01:35:22PM -0400, Jeff King wrote:\n> > On Fri, Oct 13, 2017 at 11:58:12AM +0900, 小川恭史 wrote:\n> > \n> > You can also just do:\n> > \n> >   for i in 1 2 3; do\n> >      git stash drop $i\n> >   done\n> > \n> \n> Doesn't stash 2 become stash 1 after the first drop, and the same for 3,\n> resulting in dropping stash 1, 3 and 5?\n> \n> So something like\n> \n>   for i in 3 2 1; do\n>       git stash drop $i;\n>   done\n> \n> Or leave $i out altogether.\n\nOops, you're right.\n\nFor that matter, I didn't double check that a single \"reflog delete\"\nhandles this case correctly. That should be easy to test, though:\n\n  git init\n  echo base >file\n  git add file\n  git commit -m base\n\n  for i in $(seq 10); do\n    echo $i >file\n    git stash push -m $i\n  done\n\n  git reflog delete --updateref --rewrite refs/stash@{1} refs/stash@{2} refs/stash@{3}\n\nThat seems to leave:\n\n  $ git stash list\n  stash@{0}: On master: 10\n  stash@{1}: On master: 8\n  stash@{2}: On master: 6\n  stash@{3}: On master: 4\n  stash@{4}: On master: 3\n  stash@{5}: On master: 2\n  stash@{6}: On master: 1\n\nwhich is not what we wanted (I'd guess also that it rewrites the reflog\n3 times, negating any efficiency I claimed earlier).\n\n-Peff\n"}]}