Pass an argument to a Git alias command

前端 未结 4 1335
醉话见心
醉话见心 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:25

    If you consider the Git Faq section "Git Aliases with argument", you could do it, but by calling git through a shell:

    [alias]
            rb = "!sh -c \"git rebase -i HEAD~$1\" -"
    

    I haven't tested it yet, but if you can pass an argument, that would be the way to do it.

    A similar solution would be to use a shell function:

    [alias]
            rb = "!f() { git rebase -i HEAD~$1; }; f"
    

提交回复
热议问题