Pass an argument to a Git alias command

前端 未结 4 1334
醉话见心
醉话见心 2020-11-27 16:01

Can I pass arguments to the alias of a Git command?

I have some alias in Git config, like so:

rb1 = rebase -i HEAD~1
rb2 = rebase -i HEAD~2
rb3 = reb         


        
4条回答
  •  伪装坚强ぢ
    2020-11-27 16:22

    @Droogans pointed out in a comment on the accepted answer that, at least on macOS (I would imagine the same will hold true for any unix-like OS, and maybe even windows), you can just use $1 as the placeholder value representing the argument in the alias. So, to set up an alias so that git rb 8 becomes git rebase -i HEAD~8:

        rb = "!git rebase -i HEAD~$1;"
    

    You can also use it multiple times in an alias, so if, for example, you wanted an alias that would translate git f my-branch to git fetch origin my-branch:my-branch, you can do:

        f = "!git fetch origin $1:$1"
    

提交回复
热议问题