推送git提交&


Push git commits & tags simultaneously

我知道,git push --tags是一个单独的操作,以平原老git push的原因。推标签应该是一个有意识的选择,因为你不想意外地推一个。没关系。但是有没有一种方法可以将两者结合起来呢?(除git push && git push --tags外)


2015年5月更新

从Git 2.4.1开始,您可以

1
git config --global push.followTags true

If set to true enable --follow-tags option by default. You may override this configuration at time of push by specifying --no-follow-tags.

号2013年4月更新

自Git 1.8.3(2013年4月22日)以来,您不再需要执行两个命令来推送分支,然后再推送标签:

The new"--follow-tags" option tells"git push" to push relevant annotated tags when pushing branches out.

现在,您可以在推送新提交时尝试:

1
git push --follow-tags

但是,这不会推送所有的本地标签,只会推送提交引用的那个标签,这个标签是用git push推送的。

Git 2.4.1+(2015年第2季度)将引入选项push.followTags:请参见"如何使"git push包括分支内的标签?".

原始答案,2010年9月

核选择将是git push --mirror,这将推动refs/下的所有参考。

您还可以使用当前的分支提交只推送一个标记:

1
git push origin : v1.0.0

您可以将--tags选项与refspec结合起来,例如:

1
git push origin --tags :

(由于--tags表示:除命令行明确列出的refspec外,refs/tags下的所有refs都被推送)

您还拥有这个条目"通过单个"git push"调用推送分支和标记"

A handy tip was just posted to the Git mailing list by Zoltán Füzesi:

I use .git/config to solve this:

1
2
3
4
5
[remote"origin"]
    url = ...
    fetch = +refs/heads/*:refs/remotes/origin/*
    push = +refs/heads/*
    push = +refs/tags/*

With these lines added git push origin will upload all your branches and tags. If you want to upload only some of them, you can enumerate them.

Haven't tried it myself yet, but it looks like it might be useful until some other way of pushing branches and tags at the same time is added to git push.
On the other hand, I don't mind typing:

1
$ git push && git push --tags

当心,正如Aseem Kishore所说

push = +refs/heads/*将迫使你的所有分支。

This bit me just now, so FYI.

Ren_Scheibe添加了以下有趣的评论:

The --follow-tags parameter is misleading as only tags under .git/refs/tags are considered.
If git gc is run, tags are moved from .git/refs/tags to .git/packed-refs. Afterwards git push --follow-tags ... does not work as expected anymore.


也许这对某人有帮助:

1
2
3
 1. git commit -a -m"msg"  
 2. git tag 0.1.0                // creates a new tag locally    
 3. git push origin tag 0.1.0    // pushes the tag & the code in the remote repo