Git alias with positional parameters

前端 未结 7 1025
北荒
北荒 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:34

    The most obvious way is to use a shell function:

    [alias]
        files = "!f() { git diff --name-status \"$1^\" \"$1\"; }; f"
    

    An alias without ! is treated as a Git command; e.g. commit-all = commit -a.

    With the !, it's run as its own command in the shell, letting you use stronger magic like this.

    UPD
    Because commands are executed at the root of repository you may use ${GIT_PREFIX} variable when referring to the file names in commands

提交回复
热议问题