按数字引用git stash,不包含stash @ {i} [英] Reference git stash by number without stash@{i}

查看:64
本文介绍了按数字引用git stash,不包含stash @ {i}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在广泛使用git隐藏.乍一看,只要一个简单的 3 就足够了,有时候键入 stash @ {3} 会很烦人.可以以某种方式使用较短的参考吗?

I'm using git stashes extensively. Sometimes it becomes annoying to type out stash@{3} when, at first glance, a simple 3 should suffice. Is it possible to use the shorter reference somehow?

我知道一个使用shell别名的解决方案.制作类似

I know a solution with shell aliases. Making an alias like

sshow = "!f { git stash show @{$@}; }; f"

允许使用 git sshow 1 .如果 $ @ 正确展开,它甚至可以将其他参数传递给 git stash show .

allows using git sshow 1. It even allows passing additional arguments to git stash show if $@ is expanded properly.

但是,在这种情况下,git autocomplete不起作用:键入 git stash show stash @ {0}-< Tab>< Tab> 时,它应该显示所有 gitdiff 选项,但是在这里它对基础命令一无所知.

However, in this case git autocomplete does not work: when git stash show stash@{0} --<Tab><Tab> is typed it should show all git diff options, but here it knows nothing about the underlying command.

还有其他方法可以使此类别名保留原始的 git diff 完成上下文吗?

Are there other ways of making such alias which preserve original git diff completion context?

推荐答案

是的,它是从v2.11开始内置在Git中的.您只能按索引引用任何存储.例如,要应用索引2的存储,您可以输入

Yes, this is built-in to Git as of v2.11. You can refer to any stash by index only. For example, to apply the stash at index 2 you can type

git stash apply 2

这篇关于按数字引用git stash,不包含stash @ {i}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆