将参数传递给Git别名命令 [英] Pass an argument to a Git alias command
问题描述
我可以将参数传递给Git命令的别名吗?
我在Git config中有一些别名,如下所示:
rb1 = rebase -i HEAD〜1
rb2 = rebase -i HEAD〜2
rb3 = rebase -i HEAD〜3
rb4 = rebase -i HEAD〜4
....
有可能创建一个 rb
别名,以便任何< x>对于
? git rb< x>
;
我试过这个别名:
rb = rebase -i HEAD〜
但是例如 git rb 8
不起作用。 解决方案
如果您考虑 Git Faq部分Git Aliases with argument,你可以这样做,但通过shell调用git:
[别名]
rb =!sh -c \git rebase -i HEAD〜$ 1 \ -
我还没有测试过它,但如果你能传递一个参数,那将是实现它的方法。
类似的解决方案是使用 shell函数:
[别名]
rb =!f(){git rebase -i HEAD〜$ 1;}; f
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 = rebase -i HEAD~3
rb4 = rebase -i HEAD~4
....
Is it possible to make an rb
alias so that git rb <x>
works for any <x>
?
I tried this alias:
rb = rebase -i HEAD~
but then for instance git rb 8
does not work.
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"
这篇关于将参数传递给Git别名命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!