[英]Alias for 'git stash drop' in zsh
我想創建一個alias
以在 zsh shell 中刪除 git stash。 藏匿處沒有。 我想刪除的應該作為參數傳遞給我的函數調用。
我在下面嘗試過,但它失敗了 -
function gd() {
if [ -n "$1" ]
then
git stash drop "$1"
else
echo 'Enter stash no to drop'
fi
}
它給了我以下錯誤 -
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>...]'
似乎我沒有正確傳遞參數,它被視為字符串。
我怎樣才能使這項工作?
@ShantanuTomar :您沒有定義任何別名,這首先不是一件壞事,因為無論如何函數更靈活,但是如果您真的想要alias
,則定義它的命令將是
alias gd='git stash drop'
除此之外,您的函數定義很好,盡管您不需要引用變量。 不過這樣做也無妨。
錯誤消息表明您提供的存儲不存在。 用
git stash list
獲取可用存儲的列表。
嘗試
git stash drop $1
但是,正如所評論的,zsh 不會單獨進行任何類型的轉換。
因此,請確保使用足夠新的 Git:
git stash
(然后解釋為stash@{n}
)git stash
及其索引相關的錯誤,已在 Git 2.23 中修復
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.