Git alias appending parameters to end

前端 未结 1 780
迷失自我
迷失自我 2021-02-14 19:55

I\'m using Git Bash v1.8.1, with a few aliases (for testing):

[alias]
    ekko = !echo $1 && echo $1
    ekko2 = !sh -c \'echo $1 && echo $1\'
         


        
1条回答
  •  名媛妹妹
    2021-02-14 20:13

    Your ekko2 alias is really close... What you really want is this:

    [alias]
        ekko2 = !sh -c 'echo $1 && echo $1' -
    

    Git aliases that execute shell commands do substitute the $n variables, but they also append any arguments you pass them to the end of the command. So in your first example git ekko master is equivalent to echo master && echo master master, which explains its output.

    Your second example is closer, but you're passing "master" to the sh command, which is just ignoring the extra argument. By adding - to the end of the alias, you're telling sh that the arguments that follow are intended for the script sh is executing, and not for sh itself.

    0 讨论(0)
提交回复
热议问题