同时推送 git 提交和标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3745135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Push git commits & tags simultaneously
提问by Will Robertson
I'm aware of the reason that git push --tags
is a separate operation to plain old git push
. Pushing tags should be a conscious choice since you don't want accidentally push one. That's fine. But is there a way to push both together? (Aside from git push && git push --tags
.)
我知道原因git push --tags
是普通 old 的单独操作git push
。推送标签应该是一个有意识的选择,因为您不想意外推送一个。没关系。但是有没有办法将两者推到一起?(除了git push && git push --tags
。)
回答by VonC
Update May 2015
2015 年 5 月更新
As of git 2.4.1, you can do
从git 2.4.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.
如果设置为 true,则默认启用 --follow-tags 选项。
您可以通过指定 --no-follow-tags 在推送时覆盖此配置。
As noted in this thread by Matt Rogers answering Wes Hurd:
正如马特·罗杰斯在回答韦斯·赫德时所指出的:
--follow-tags
only pushes annotated tags.
--follow-tags
只推送带注释的标签。
git tag -a -m "I'm an annotation" <tagname>
That would be pushed (as opposed to git tag <tagname>
, a lightweight tag, which would not be pushed, as I mentioned here)
这将被推送(而不是git tag <tagname>
轻量级标签,不会被推送,正如我在这里提到的)
Update April 2013
2013 年 4 月更新
Since git 1.8.3 (April 22d, 2013), you no longer have to do 2 commands to push branches, and then to push tags:
从git 1.8.3 (April 22d, 2013) 开始,您不再需要执行 2 个命令来推送分支,然后推送标签:
The new "
--follow-tags
" option tells "git push
" to push relevant annotated tags when pushing branches out.
新的“
--follow-tags
”选项告诉“git push
”在推出分支时推出相关的注释标签。
You can now try, when pushing new commits:
您现在可以在推送新提交时尝试:
git push --follow-tags
That won't push allthe local tags though, only the one referenced by commits which are pushed with the git push
.
不过,这不会推送所有本地标签,只会推送由git push
.
Git 2.4.1+ (Q2 2015) will introduce the option push.followTags
: see "How to make “git push
” include tags within a branch?".
Git 2.4.1+(2015 年第 2 季度)将引入选项push.followTags
:请参阅“如何使“ git push
”在分支中包含标签?”。
Original answer, September 2010
原始答案,2010 年 9 月
The nuclear option would be git push --mirror
, which will push all refs under refs/
.
核选项将是git push --mirror
,这将推动所有裁判refs/
。
You can also push just one tag with your current branch commit:
您还可以使用当前分支提交只推送一个标签:
git push origin : v1.0.0
You can combine the --tags
option with a refspec like:
您可以将该--tags
选项与 refspec结合使用,例如:
git push origin --tags :
(since --tags
means: All refs under refs/tags
are pushed, in addition to refspecs explicitly listed on the command line)
(因为--tags
意味着:除了在命令行上明确列出的 refspecs 之外,所有 refsrefs/tags
都被推送)
You also have this entry "Pushing branches and tags with a single "git push" invocation"
您还有这个条目“使用单个“git push”调用推送分支和标签”
A handy tip was just posted to the Git mailing listby Zoltán Füzesi:
I use
.git/config
to solve this:
Zoltán Füzesi刚刚在Git 邮件列表中发布了一个方便的提示:
我
.git/config
用来解决这个问题:
[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:
添加这些
git push origin
行将上传您所有的分支和标签。如果您只想上传其中的一部分,您可以枚举它们。我自己还没有尝试过,但看起来它可能很有用,直到将其他同时推送分支和标签的方式添加到 git push 之前。
另一方面,我不介意打字:
$ git push && git push --tags
Beware, as commentedby Aseem Kishore
小心,正如阿西姆·基肖尔 (Aseem Kishore)评论的那样
push = +refs/heads/*
will force-pushes all your branches.
push = +refs/heads/*
将强制推动您的所有分支。
This bit me just now, so FYI.
刚才这有点我,所以仅供参考。
René Scheibeadds this interesting comment:
The
--follow-tags
parameter is misleading as only tags under.git/refs/tags
are considered.
Ifgit gc
is run, tags are moved from.git/refs/tags
to.git/packed-refs
. Afterwardsgit push --follow-tags ...
does not work as expected anymore.
该
--follow-tags
参数具有误导性,因为只.git/refs/tags
考虑下面的标签。
如果git gc
运行,标签从 移动.git/refs/tags
到.git/packed-refs
。之后git push --follow-tags ...
不再按预期工作。
回答by Rajesh Gupta
Maybe this helps someone:
也许这有助于某人:
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
回答by SoBeRich
@since Git 2.4
@从 Git 2.4 开始
git push --atomic origin <branch name> <tag>
git push --atomic origin <branch name> <tag>
回答by Ivan
Git GUI has a PUSH button - pardon the pun, and the dialog box it opens has a checkbox for tags.
Git GUI 有一个 PUSH 按钮 - 请原谅双关语,它打开的对话框有一个标记复选框。
I pushed a branch from the command line, without tags, and then tried again pushing the branch using the --follow-tags
option descibed above. The option is described as following annotated tags. My tags were simple tags.
我从命令行推送了一个分支,没有标签,然后使用--follow-tags
上面描述的选项再次尝试推送分支。该选项被描述为以下带注释的标签。我的标签是简单的标签。
I'd fixed something, tagged the commit with the fix in, (so colleagues can cherry pick the fix,) then changed the software version number and tagged the release I created (so colleagues can clone that release).
我修复了一些东西,用修复标记提交,(这样同事可以挑选修复,)然后更改软件版本号并标记我创建的版本(这样同事可以克隆该版本)。
Git returned saying everything was up-to-date. It did not send the tags! Perhaps because the tags weren't annotated. Perhaps because there was nothing new on the branch.
Git 回来说一切都是最新的。它没有发送标签!也许是因为标签没有注释。也许是因为树枝上没有什么新东西。
When I did a similar push with Git GUI, the tags were sent.
当我用 Git GUI 做一个类似的推送时,标签被发送了。
For the time being, I am going to be pushing my changes to my remotes with Git GUI and not with the command line and --follow-tags
.
目前,我将使用 Git GUI 而不是命令行和--follow-tags
.