我想为以下内容编写一个 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 search "Big boi"
我还使其与 --grep=\"$str\"
一起使用(并且仍然使用双引号)
OP joshuatvernon添加in the comments :
I amended it to
search = "!f() { str="$*"; echo "$str"; git log --all --grep=\"$str\"; }; f"
and it works with single, double or no quotes.
关于git - 如何编写一个以字符串作为参数的 git 别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49040686/