简体   繁体   中英

Alias for 'git stash drop' in zsh

I want to make an alias to drop a git stash in zsh shell. 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

 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.

So, make sure to use a recent enough Git:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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