views:

36

answers:

2

Basically I'm trying to alias:

git files 9fa3

...to execute the command:

 git diff --name-status 9fa3^ 9fa3

but git doesn't appear to pass positional parameters to the alias command. I have tried:

[alias]
    files = "!git diff --name-status $1^ $1"
    files = "!git diff --name-status {1}^ {1}"

...and a few others but those didn't work.

The degenerate case would be:

 $ git echo_reverse_these_params a b c d e
 e d c b a

...how can I make this work?

+1  A: 

The most obvious way is to use a shell function:

[alias]
    files = "!f() { git diff --name-status $1^ $1; }; f"
Jefromi
Thanks, this looks exactly right:[alias] files = "!f() { echo $3 $2 $1; }; f" ; $ git files a b c =>c b a
+1  A: 

You can also reference sh directly (instead of creating a function):

[alias]
        files = !sh -c 'git diff --name-status $1^ $1' -

(Note the dash at the end of the line -- you'll need that.)

mipadi
...are there any tangible benefits as compared to jefromi's answer? I mean: the function def in his answer is "alias-local" and means you don't have bash calling bash, right? In any case thanks for the alternative implementation.
I don't think either solution really has benefits over the other -- just two different ways to do the same thing.
mipadi