简体   繁体   English

zsh 中“git stash drop”的别名

[英]Alias for 'git stash drop' in zsh

I want to make an alias to drop a git stash in zsh shell.我想创建一个alias以在 zsh shell 中删除 git stash。 The stash no.藏匿处没有。 which I want to drop should be passed as an argument to my function call.我想删除的应该作为参数传递给我的函数调用。

I have tried below but it is failing -我在下面尝试过,但它失败了 -

function gd() {
    if [ -n "$1" ]
    then
        git stash drop "$1"
    else
        echo 'Enter stash no to drop'
    fi
}

It gives me below error -它给了我以下错误 -

fatal: ambiguous argument '0': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Seems I am not passing the argument correctly and it is being treated as a string.似乎我没有正确传递参数,它被视为字符串。

How can I make this work?我怎样才能使这项工作?

@ShantanuTomar : You don't define any alias, which is not a bad thing in the first place, because a function is more flexible anyway, but if you really want to have an alias , the command to define it would be @ShantanuTomar :您没有定义任何别名,这首先不是一件坏事,因为无论如何函数更灵活,但是如果您真的想要alias ,则定义它的命令将是

 alias gd='git stash drop'

Aside from this, your function definition is fine, though you don't need to quote your variables.除此之外,您的函数定义很好,尽管您不需要引用变量。 It doesn't harm doing so, though.不过这样做也无妨。

The error message says that the stash you provided, does not exist.错误消息表明您提供的存储不存在。 Use

git stash list

to get a list of the available stashes.获取可用存储的列表。

Try尝试

git stash drop $1

But, as commented, there won't be any kind of conversion done by zsh alone.但是,正如所评论的,zsh 不会单独进行任何类型的转换。

So, make sure to use a recent enough Git:因此,请确保使用足够新的 Git:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM