2016-10-07 52 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.