我怎样才能编写一个以字符串作为参数的git别名

问题描述 投票:1回答:1

我想写一个git别名:

git log --all --grep='Big boi'

到目前为止我所拥有的是:

[alias]
    search = "!f() { str=${@}; echo $str; git log --all --grep=$str; }; f"

哪个回声字符串完全正常但是给出了错误,我似乎无法弄清楚如何将字符串传递给grep标志。

$ user in ~/src/repo on master λ git search 'Big boi'
Big boi
fatal: ambiguous argument 'boi': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

如果它有任何区别我正在使用zsh。 。 。

git zsh git-alias git-grep
1个回答
3
投票

如果您使用双引号,该别名似乎有效:

git search "Big boi"

我也使它与--grep=\"$str\"(仍然使用双引号)

OP joshuatvernon添加in the comments

我修改了它

search = "!f() { str="$*"; echo "$str"; git log --all --grep=\"$str\"; }; f"

它适用于单引号,双引号或无引号。

© www.soinside.com 2019 - 2024. All rights reserved.