Olivier Refalo
Olivier Refalo

Reputation: 51435

Passing all parameters to a git alias

To simplify my concern, I narrowed it to the following:

I have a GIT alias defined as such:

cii = "!f() { git commit "$@"; }; f"

When I run

$ git cii -m "test1"

It works fine, but it fails with

$ 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.

Any idea ?

Note that my real alias is much more complex that the above, so responding with cii = "commit" is not an option. The point here is passing the input parameters to the function.

Upvotes: 6

Views: 1073

Answers (1)

geekosaur
geekosaur

Reputation: 61369

You need to quote the embedded doublequotes.

cii = "!f() { git commit \"$@\"; }; f"

git will then perform standard shell expansion of "$@" which translates to a single word for each parameter - like "$1" "$2" "$3" ...

Upvotes: 7

Related Questions