为了简化我的顾虑,我将其缩小到以下几点:
我有一个GIT别名定义如下:
cii = "!f() { git commit "$@"; }; f"
Run Code Online (Sandbox Code Playgroud)
我跑的时候
$ git cii -m "test1"
Run Code Online (Sandbox Code Playgroud)
它工作正常,但失败了
$ git cii -m "test1 and test2"
error: pathspec 'and' did not match any file(s) known to git.
error: pathspec 'test2' did not match any file(s) known to git.
Run Code Online (Sandbox Code Playgroud)
任何的想法 ?
请注意,我的真正别名比上面复杂得多,因此使用cii ="commit"进行响应不是一种选择.这里的要点是将输入参数传递给函数.
您需要引用嵌入式双引号.
cii = "!f() { git commit \"$@\"; }; f"
Run Code Online (Sandbox Code Playgroud)
然后git将执行标准的shell扩展,"$@"
其中每个参数转换为一个单词 - 就像"$1" "$2" "$3" ...