使用参数创建git别名

使用参数创建git别名,git,Git,我编写了以下git别名,将我的提交推送到origin,并使用传递给别名的参数对其进行标记,然后也推送标记 pomt = !git push origin master && git tag '$1' && git push --tag 用法: git pomt myTagGoesHere 但是,此操作失败并出现错误 致命的“MyTagGoesher”似乎不是git存储库 从那以后,我发现实现这一目标还有其他选择 但是我很好奇我所创建的别名有什么问题,我仍然想

我编写了以下git别名,将我的提交推送到origin,并使用传递给别名的参数对其进行标记,然后也推送标记

pomt = !git push origin master && git tag '$1' && git push --tag
用法:

git pomt myTagGoesHere
但是,此操作失败并出现错误

致命的“MyTagGoesher”似乎不是git存储库

从那以后,我发现实现这一目标还有其他选择

但是我很好奇我所创建的别名有什么问题,我仍然想知道如何以这种方式创建别名,只是为了学习如何使用参数创建别名


这是在Windows上,顺便说一句,如果这对shell脚本有任何影响,您可以使用shell函数:

pomt = "!f(){ git push origin master && git tag \"$1\"  && git push --tag; };f"
注意:我建议使用created而不是轻量级的


备选方案:

%PATH%
上的任意位置创建一个名为
git pomt
的脚本(无扩展):它将是常规bash脚本(同样,即使在Windows上也能工作,因为它是由git bash解释的)

在该脚本中,您可以定义所需的任何命令序列,并且仍然可以使用
git-pomt-mytag
调用它(no'-':
git-pomt


git别名将按原样使用附加到alias命令行的参数进行调用。命名参数(
$1
$2
等)在命令行中展开的事实并不妨碍将这些参数追加到展开的alias命令中

在你的例子中

git pomt myTagGoesHere
扩展到

git push origin master && git tag myTagGoesHere && git push --tag myTagGoesHere
#                                                                 ^^^^^^^^^^^^^^
因此,
mytaggoesher
也被传递到
git push
命令,从而导致观察到的错误

已经。另一种解决方案是将参数提供给no op命令:

pomt = !git push origin master && git tag '$1' && git push --tag && :
编辑

顺便说一句,您可以通过在shell git别名前面加上
set-x
来调试它的操作:

$ git config alias.pomt '!set -x; git push origin master && git tag $1 && git push --tags'
$ git pomt tag5
+ git push origin master
Everything up-to-date
+ git tag tag5
+ git push --tags tag5
fatal: 'tag5' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

谢谢-几个小错误-在最后一次git推送之前有两组符号。它需要一组引号在开头。谢谢大家给我讲解注释tags@ChrisCa右图:修正。干杯-再开放几个小时,看看其他有趣的答案-谢谢again@ChrisCa当然我已编辑了我的答案以添加备选答案
$ git config alias.pomt '!set -x; git push origin master && git tag $1 && git push --tags'
$ git pomt tag5
+ git push origin master
Everything up-to-date
+ git tag tag5
+ git push --tags tag5
fatal: 'tag5' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.