如何使用 Git 将标签推送到远程存储库?

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

How do you push a tag to a remote repository using Git?

gitrepositorypushgit-pushgit-tag

提问by Jonas

I have cloned a remote Git repository to my laptop, then I wanted to add a tag so I ran

我已经将远程 Git 存储库克隆到我的笔记本电脑,然后我想添加一个标签,所以我跑了

git tag mytag master

When I run git tagon my laptop the tag mytagis shown. I then want to push this to the remote repository so I have this tag on all my clients, so I run git pushbut I got the message:

当我git tag在笔记本电脑上运行时,mytag会显示标签。然后我想把它推送到远程存储库,这样我的所有客户端上都有这个标签,所以我运行git push但我收到了消息:

Everything up-to-date

一切都是最新的

And if I go to my desktop and run git pulland then git tagno tags are shown.

如果我转到桌面并运行git pull,则git tag不会显示任何标签。

I have also tried to do a minor change on a file in the project, then push it to the server. After that I could pull the change from the server to my Desktop computer, but there's still no tag when running git tagon my desktop computer.

我也尝试对项目中的文件做一个小改动,然后将其推送到服务器。之后,我可以将更改从服务器拉到我的台式计算机上,但是git tag在我的台式计算机上运行时仍然没有标签。

How can I push my tag to the remote repository so that all client computers can see it?

如何将我的标签推送到远程存储库,以便所有客户端计算机都可以看到它?

回答by Trevor

To push a singletag:

推送单个标签:

git push origin <tag_name>

And the following command should push alltags (not recommended):

并且以下命令应该推送所有标签(不推荐):

git push --tags

回答by solgar

To push specific, one tag do following git push origin tag_name

要推送具体,一个标签做以下 git push origin tag_name

回答by solgar

To expand on Trevor's answer, you can push a single tag or all of your tags at once.

要扩展Trevor 的答案,您可以一次推送单个标签或所有标签。

Push a Single Tag

推送单个标签

git push <remote> <tag>

This is a summary of the relevant documentationthat explains this (some command options omitted for brevity):

这是解释这一点的相关文档的摘要(为简洁起见,省略了一些命令选项):

git push [[<repository> [<refspec>…]]

<refspec>...

The format of a <refspec>parameter is…the source ref <src>, followed by a colon :, followed by the destination ref <dst>

The <dst>tells which ref on the remote side is updated with this push…If :<dst>is omitted, the same ref as <src>will be updated…

tag <tag>means the same as refs/tags/<tag>:refs/tags/<tag>.

git push [[<repository> [<refspec>…]]

<refspec>...

<refspec>参数的格式是……源引用<src>,后跟冒号:,后跟目标引用<dst>……

<dst>该裁判在远程端与此更新推...讲述如果:<dst>省略,同样的裁判作为<src>将被更新...

标签的<tag>含义与refs/tags/<tag>:refs/tags/<tag>.

Push All of Your Tags at Once

一次性推送所有标签

git push --tags <remote>
# Or
git push <remote> --tags

Here is a summary of the relevant documentation(some command options omitted for brevity):

以下是相关文档的摘要(为简洁起见省略了一些命令选项):

git push [--all | --mirror | --tags] [<repository> [<refspec>…]]

--tags

All refs under refs/tagsare pushed, in addition to refspecs explicitly listed on the command line.

git push [--all | --mirror | --tags] [<repository> [<refspec>…]]

--tags

refs/tags除了命令行上明确列出的 refspecs 之外,所有 refs都被推送。

回答by Ashutosh Meher

Tags are not sent to the remote repository by the git push command. We need to explicitly send these tags to the remote server by using the following command:

git push 命令不会将标签发送到远程存储库。我们需要使用以下命令将这些标签显式发送到远程服务器:

git push origin <tagname>

We can push all the tags at once by using the below command:

我们可以使用以下命令一次性推送所有标签:

git push origin --tags

Here are some resources for complete details on git tagging:

以下是有关 git 标记的完整详细信息的一些资源:

http://www.cubearticle.com/articles/more/git/git-tag

http://www.cubearticle.com/articles/more/git/git-tag

http://wptheming.com/2011/04/add-remove-github-tags

http://wptheming.com/2011/04/add-remove-github-tags

回答by Sajib Khan

You can push all local tags by simply git push --tagscommand.

您可以通过简单的git push --tags命令推送所有本地标签。

$ git tag                         # see tag lists
$ git push origin <tag-name>      # push a single tag
$ git push --tags                 # push all local tags 

回答by Fernando Diaz Garrido

You can push the tags like this git push --tags

你可以像这样推送标签 git push --tags

回答by Carl G

I am using git push <remote-name> tag <tag-name>to ensure that I am pushing a tag. I use it like: git push origin tag v1.0.1. This pattern is based upon the documentation (man git-push):

我正在使用git push <remote-name> tag <tag-name>以确保我正在推送标签。我使用它像:git push origin tag v1.0.1。此模式基于文档 ( man git-push):

OPTIONS
   ...
   <refspec>...
       ...
       tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>.