git 标签也会被推送吗?

发布于 2024-09-04 03:42:05 字数 147 浏览 3 评论 0原文

自从我创建了我的存储库以来,我所使用的标签似乎 创建不会被推送到存储库。当我在上执行 git tag 时 本地目录所有标签都存在,但是当我登录到 远程存储库并执行 git tag,仅显示前几个。

可能是什么问题?

Since I created my repository it appears that the tags I have been
creating are not pushed to the repository. When I do git tag on 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.

What could the problem be?.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

小女人ら 2024-09-11 03:42:05

你可以这样做:

git push --tags

You could do this:

git push --tags
极致的悲 2024-09-11 03:42:05

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

$ git push <remote> tag <tagname>

推送单个标签,或

$ git push <remote> --tags

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

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


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

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

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

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

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

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

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


或者,您可以将推送的远程配置为始终推送所有标签,例如在您的 .git/config 中放入类似的内容:

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

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

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

$ git push <remote> tag <tagname>

to push a single tag, or

$ git push <remote> --tags

to push all tags (or git push --tags to push to default remote, usually 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)

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.

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

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:

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

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

马蹄踏│碎落叶 2024-09-11 03:42:05

请注意,自 git 1.8.3(4 月22d, 2013),你不再需要执行 2 个命令来推送分支,然后推送标签:

新的“--follow-tags”选项告诉“git push在推出分支时推送相关的带注释的标签。< /p>

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

git push --follow-tags

但这不会推送所有本地标记,只会推送使用 推送的提交引用的带注释标记git 推送


这是由 commit c2aba15 引入的。 com/gitster" rel="noreferrer">Junio C Hamano (gitster):

新选项“--follow-tags”告诉“git push”推送另一侧缺少的带注释的标签,并且可以通过否则就会被淘汰的历史。

例如,如果您使用“simple”、“current”或“upstream”推送,则通常会推送导致在当前 HEAD 进行提交的历史记录,仅此而已。
使用此选项,您还可以将可以从该提交到达的所有带注释的标签推送到另一端。


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

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:

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

You can now try, when pushing new commits:

git push --follow-tags

That won't push all the local tags though, only the annotated ones referenced by commits which are pushed with the git push.


This has been introduced in commit c2aba15 by Junio C Hamano (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 HEAD and nothing else.
With this option, you would also push all annotated tags that can be reached from that commit to the other side.


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

年华零落成诗 2024-09-11 03:42:05

我通常做的是:

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

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

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.

向地狱狂奔 2024-09-11 03:42:05

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

git config remote.origin.tagopt --tags

来自文档:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文