Mercurial: alias with arguments

丶灬走出姿态 提交于 2020-01-03 20:56:17

问题


I want to create an alias so that when I run:

hg pushbranch <<SOME_BRANCH>>

it aliases to:

hg push -b <<SOME_BRANCH>>

Where SOME_BRANCH is the name of a branch I wish to push. I can create an alias in my .hgrc, but don't know how I could supply an argument to the alias.


回答1:


From the hgrc help

Positional arguments in the form of $1, $2, etc in the alias definition are expanded by Mercurial before execution.

Thus, your alias definition, which will allow to push any branch, will be

pushbranch = push -b $1

and hg pushbranch mybranch is expanded to hg push -b mybranch




回答2:


You can simply add the arguments in your alias. Some examples from my configuration:

[alias]
log0 = log -l 10
tipr = tip --template "{node|short}"

If you provide additional arguments, they'll simply be appended. For example, the following will be functionally equivalent to log -l 10 -k Refactoring.

$ hg log0 -k Refactoring


来源:https://stackoverflow.com/questions/31009414/mercurial-alias-with-arguments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!