2016-10-07 45 views
5

我写了下面的git的别名来推我提交原产地,并传递给别名paramater标记,然后将标记推过创建一个Git别名与

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

使用参数:

git pomt myTagGoesHere 

然而,这失败,错误

致命 'myTagGoesHere' 并不似乎是一个git仓库

因为我已经发现有实现这一 Push git commits & tags simultaneously

其他选择,但我很好奇,什么是错的我已经创建了别名,并仍想知道如何做到这一点只是这样学习如何创建参数

这是在Windows上,顺便说一句,如果别名说对shell脚本

回答

1

您可以改用壳功能的差异的缘故:

pomt = "!f(){ git push origin master && git tag \"$1\" && git push --tag; };f" 

注:我会建议创建an annotated tag而不是轻量级的。


备选:

建立一个叫做git-pomt%PATH%(没有扩展名)的任何地方脚本:它会定期bash脚本(再次,作品即使是在Windows,因为它是由Git的bash的解释)

在这个脚本,你可以定义你想命令的任何序列,你还是会用git pomt mytag调用它(没有“ - ”:git pomt

#!/bin/bash 
git push origin master 
git tag $1 
git push --tag 
+0

感谢 - 几个小错别字 - 在最终的git推动之前有两组&符号。它在开始时需要一组引号。感谢您在标注标签上的单挑 – ChrisCa

+0

@ChrisCa右:修正。 – VonC

+0

欢呼声 - 留下这个打开几个小时只是为了看到其他有趣的答案 - 再次感谢 – ChrisCa

1

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

在您的例子

git pomt myTagGoesHere 

被扩大到

git push origin master && git tag myTagGoesHere && git push --tag myTagGoesHere 
#                 ^^^^^^^^^^^^^^ 

因此myTagGoesHere被传递到git push命令以及,导致所观察到的误差。

VonC已经showed how to circumvent that problem through an introduction of a (temporary) function。另一个解决方案是将参数馈送到无操作的命令:

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

EDIT

顺便说一句,可以通过在前面它具有set -x调试壳的git别名的操作:

$ 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.