Git alias with positional parameters

前端 未结 7 1003
北荒
北荒 2020-11-22 12:35

Basically I\'m trying to alias:

git files 9fa3

...to execute the command:

git diff --name-status 9fa3^ 9fa3
7条回答
  •  深忆病人
    2020-11-22 13:18

    Use GIT_TRACE=1 described on the git man page to make the alias processing transparent:

    $ git config alias.files
    !git diff --name-status $1^ $1
    $ GIT_TRACE=1 git files 1d49ec0
    trace: exec: 'git-files' '1d49ec0'
    trace: run_command: 'git-files' '1d49ec0'
    trace: run_command: 'git diff --name-status $1^ $1' '1d49ec0'
    trace: exec: '/bin/sh' '-c' 'git diff --name-status $1^ $1 "$@"' 'git diff --name-status $1^ $1' '1d49ec0'
    trace: built-in: git 'diff' '--name-status' '1d49ec0^' '1d49ec0' '1d49ec0'
    trace: run_command: 'less -R'
    trace: exec: '/bin/sh' '-c' 'less -R' 'less -R'
    MM      TODO
    

    Your original commands work with git version 1.8.3.4 (Eimantas noted this changed in 1.8.2.1).

    The sh -c '..' -- and f() {..}; f options both cleanly handle the "$@" parameters in different ways (see with GIT_TRACE). Appending "#" to an alias would also allow positional parameters without leaving the trailing ones.

提交回复
热议问题