git 标签也会被推送吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2988088/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:31:52  来源:igfitidea点击:

Do git tags get pushed as well?

gitgit-tag

提问by vfclists

Since I created my repository it appears that the tags I have been creating are not pushed to the repository. When I do git tagon the local directory all the tags are present, but when I logon to the remote repository and do a git tag, only the first few show up.

由于我创建了我的存储库,似乎我一直在创建的标签没有被推送到存储库。当我git tag在本地目录上执行时,所有标签都存在,但是当我登录到远程存储库并执行 a 时git tag,只显示前几个。

What could the problem be?.

可能是什么问题?

回答by eevar

You could do this:

你可以这样做:

git push --tags

回答by Jakub Nar?bski

In default git remote configuration you have to push tags explicitly(while they are fetched automaticallytogether with commits they point to). You need to use

在默认的 git 远程配置中,您必须显式推送标签(同时它们会与它们指向的提交一起自动获取)。你需要使用

$ git push <remote> tag <tagname>

to push a single tag, or

推送单个标签,或

$ git push <remote> --tags

to push all tags (or git push --tagsto push to default remote, usually origin).

推送所有标签(或git push --tags推送到默认远程,通常origin)。

This is very much intended behavior, to make pushing tags explicit. Pushing tags should be usually conscious choice.

这是非常有意的行为,使推送标签明确。推送标签通常应该是有意识的选择。



Summarizing what Junio C. Hamano wrote(linked in comments by @Andre Miras)

总结 Junio C. Hamano写的内容(在@Andre Miras 的评论中链接)

When fetching, you are interacting with a remote repository somebody has published, which means:

  1. the set of tags that exist there are all the publisher wanted people to see, and
  2. not only you but other people will also see the same tags.

In other words, tags in repositories you fetch from are designed to be public and shared. It will facilitate communication between developers if it is easy for everybody to fetch these same tags.

获取时,您正在与某人发布的远程存储库进行交互,这意味着:

  1. 存在的标签集是发布商希望人们看到的所有标签,以及
  2. 不仅您,其他人也会看到相同的标签。

换句话说,您从中获取的存储库中的标签被设计为公开和共享的。如果每个人都可以轻松获取这些相同的标签,这将有助于开发人员之间的交流。

That's why git fetchautomatically "follows" tags, i.e. it downloads tags when downloading revisions they point to - in other words downloads all relevant publishedtags.

这就是为什么会git fetch自动“跟随”标签,即在下载它们指向的修订时下载标签 - 换句话说,下载所有相关的已发布标签。

When pushing, you are pushing from your working repository, which most of the time is not public, and tags in that repository is not designed to be public. You can use your own local tags to mark your progress, so it does not make sense to blindly push all tags in your repository to the repository you are pushing to publish your changes, whose tags are by definition public.

推送时,您正在从您的工作存储库推送,该存储库大部分时间都不是公开的,并且该存储库中的标签并非设计为公开的。您可以使用自己的本地标签来标记您的进度,因此盲目地将存储库中的所有标签推送到您正在推送的存储库以发布更改是没有意义的,其标签根据定义是公开的。

That's why you need to push tag explicitly, to mark tag as public.

这就是为什么您需要显式推送标签,将标签标记为公开。



Alternatively you can configure the remote you push to to always push all tags, e.g. put something like that in your .git/config:

或者,您可以将推送到的遥控器配置为始终推送所有标签,例如在您的.git/config:

[remote "publish"] # or whatever it is named
    url = ...
    push = +refs/heads/*:refs/heads/*
    push = +refs/tags/*:refs/tags/*

This means forcepush all heads (all branches) and all tags (if you don't want force pushing of heads, remove '+' prefix from refspec).

这意味着强制推送所有头部(所有分支)和所有标签(如果您不想强制推送头部,请从 refspec 中删除 '+' 前缀)。

回答by VonC

Note that 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 annotatedones referenced by commits which are pushed with the git push.

这不会推动所有的局部变量,虽然,只有注释通过提交引用那些被推向与git push



This has been introduced in commit c2aba15by Junio C Hamano (gitster):

这已被引入提交c2aba15通过JUNIOÇ滨野(gitster

The new option "--follow-tags" tells "git push" to push annotated tags that are missing from the other side and that can be reached by the history that is otherwise pushed out.

For example, if you are using the "simple", "current", or "upstream" push, you would ordinarily push the history leading to the commit at your current HEADand nothing else.
With this option, you would also push all annotated tags that can be reached from that commit to the other side.

新选项“ --follow-tags”告诉“ git push”推送另一侧缺少的注释标签,并且可以通过其他方式推送的历史记录到达。

例如,如果您使用“ simple”、“ current”或“ upstream”推送,您通常会推送导致当前提交的历史记录,HEAD而不是其他任何内容。
使用此选项,您还可以将可以从该提交到达的所有带注释的标签推送到另一端。



The config push.followTagsallows to include --follow-tagsby default (Git 2.4.1+, Q2 2015).   See "Push git commits & tags simultaneously"

默认情况下,配置push.followTags允许包含--follow-tags(Git 2.4.1+,2015 年第二季度)。请参阅“同时推送 git 提交和标签

回答by mat

What I usually do is :

我通常做的是:

[remote "publish"] # or whatever it is named
    url = ...
    push = :
    push = +refs/tags/*:refs/tags/*

Meaning it pushes every branch that's already there, plus tags. It does not force push, and it does not push branch that you didn't push manually.

这意味着它会推送已经存在的每个分支,以及标签。它不会强制推送,也不会推送您没有手动推送的分支。

回答by boryn

And if you want to force fetch all the tags, you may set it in the config by:

如果你想强制获取所有标签,你可以通过以下方式在配置中设置它:

git config remote.origin.tagopt --tags

From the docs:

从文档:

Setting this value to --no-tags disables automatic tag following when fetching from remote . Setting it to --tags will fetch every tag from remote , even if they are not reachable from remote branch heads. Passing these flags directly to git-fetch(1) can override this setting. See options --tags and --no-tags of git-fetch(1).

将此值设置为 --no-tags 会在从 remote 获取时禁用自动标记跟随。将其设置为 --tags 将从 remote 获取每个标签,即使它们无法从远程分支头访问。将这些标志直接传递给 git-fetch(1) 可以覆盖此设置。请参阅 git-fetch(1) 的选项 --tags 和 --no-tags。