git stash drop最旧的存储(例如最旧的5个存储)

编程入门 行业动态 更新时间:2024-10-24 15:18:10
本文介绍了git stash drop最旧的存储(例如最旧的5个存储)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在一个语句中删除最旧的存储区(例如最旧的5个存储区),而不是执行以下操作:

How do I drop oldest stashes (say oldest 5 stashes) in one statement instead of doing something like this:

git stash drop stash@{3} git stash drop stash@{4} git stash drop stash@{5} git stash drop stash@{6} git stash drop stash@{7}

推荐答案

感谢匿名用户的编辑,正确的命令应如下所示:

Thanks to an anonymous user's edit, the correct command would look like this:

git stash list | cut -f 1 -d : | tail -5 | sort -r | xargs -n 1 git stash drop

这是他/她的解释:

  • git隐藏列表:列出所有隐藏列表
  • cut -f 1 -d :仅选择第一列(存储标识符,例如stash @ {29})
  • tail -5 :仅保留最后五行
  • sort -r :反转行的顺序以首先删除最旧的存储区(否则,其余的存储区在每次删除后都会获得新名称)
  • xargs -n 1 git stash drop :对于管道中传输的每一行,执行git stash drop,因为 git stash drop [可能]仅支持一个stash a.时间.
  • git stash list: List all your stashes
  • cut -f 1 -d: Select only the first column (stash identifier, for example stash@{29})
  • tail -5: Keep only the last five lines
  • sort -r: Invert the order of the lines to drop the oldest stash first (otherwise remaining stashes get new names after each removal)
  • xargs -n 1 git stash drop: For each line transmitted in the pipe, execute git stash drop, since git stash drop [may] support only one stash a time.

所有对神秘陌生人的敬意.

All kudos to the mysterious stranger.

更多推荐

git stash drop最旧的存储(例如最旧的5个存储)

本文发布于:2023-10-27 23:32:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534858.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:git   stash   drop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!