Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing all parameters to a git alias

Tags:

git

bash

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.

like image 433
Olivier Refalo Avatar asked Apr 20 '12 18:04

Olivier Refalo


People also ask

What is Git alias?

Git aliases are a powerful workflow tool that create shortcuts to frequently used Git commands. Using Git aliases will make you a faster and more efficient developer. Aliases can be used to wrap a sequence of Git commands into new faux Git command.

What is exclamation in Git?

That means the Git status is normal. As soon as you start editing a file, the status changes to modified and the icon overlay then changes to a red exclamation mark. That way you can easily see which files were changed since you last updated your working tree and need to be committed.

What is the Git commit command?

The "commit" command is used to save your changes to the local repository. Note that you have to explicitly tell Git which changes you want to include in a commit before running the "git commit" command. This means that a file won't be automatically included in the next commit just because it was changed.

What Git add does?

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .


1 Answers

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

like image 197
geekosaur Avatar answered Oct 23 '22 03:10

geekosaur