Syntax for Git aliases with multiple commands

后端 未结 4 897
滥情空心
滥情空心 2020-12-08 13:42

I want to create a Git alias to perform multiple commands, but I cant find documentation on how this is done.

  1. What is the syntax for Git aliases with multiple
4条回答
  •  隐瞒了意图╮
    2020-12-08 13:59

    Addendum Answer: Often I need more complex commands that decide what to do through positional parameters and branch on the parameters or loop through parameters or input files.

    Such commands are too complex for single liners and they are hard to read and edit on one line. But I found a real simple method to do very complex commands from files:

    Assume you have a file called alias/cmd in your repository:

    !function f {
        if [ -z "$1" ]
        then echo "Please give me some argument!" 1>&2
            exit -1
        fi
        echo "Hello $1"
    }; f
    

    then you can simply say

    git config alias.cmd "`cat alias/cmd`"
    

    to define the alias cmd from the file and

    git config --get alias.cmd > alias/cmd
    

    to write the defined alias to the file.

提交回复
热议问题