如何使用 Git 将标签推送到远程存储库?
我在我的机器上的 master 分支上添加了一个标签:
git tag mytag master
How do I Push this to the Remote Repository?运行 git push 会显示以下消息:
一切都是最新的
但是,远程存储库不包含我的标签。
I added a tag to the master branch on my machine:
git tag mytag master
How do I push this to the remote repository? Running git push
gives the message:
Everything up-to-date
However, the remote repository does not contain my tag.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
推送单个标签:
以下命令应推送所有标签(不推荐):
To push a single tag:
And the following command should push all tags (not recommended):
git push --follow-tags
这是 Git 1.8.3 中引入的一个明智的选项:
它推送两个提交,并且只推送两者都具有的标记:
这是明智的,因为:
。应避免
--tags
的原因。Git 2.4 添加了
push.followTags
选项来开启默认情况下,您可以通过以下方式设置标记:或者将
followTags = true
添加到~/.gitconfig
文件的[push]
部分。Visual Studio Code
要在 Visual Studio Code 中激活此功能,请在用户或工作区的基础上设置变量
"git.followTagsWhenSync": true
。 GitHubgit push --follow-tags
This is a sane option introduced in Git 1.8.3:
It pushes both commits and only tags that are both:
This is sane because:
It is for those reasons that
--tags
should be avoided.Git 2.4 has added the
push.followTags
option to turn that flag on by default which you can set with:or by adding
followTags = true
to the[push]
section of your~/.gitconfig
file.Visual Studio Code
To activate this in Visual Studio Code set the variable
"git.followTagsWhenSync": true
on a user or workspace basis. GitHub要推送特定内容,一个标签执行以下操作
git Push origin tag_name
To push specific, one tag do following
git push origin tag_name
要扩展 Trevor 的答案,您可以推送单个标签或所有标签
立即标记。
推送单个标签
这是相关文档的摘要< /a> 解释了这一点(一些
为简洁起见,省略命令选项):
一次推送所有标签
这是 的摘要相关文档(一些命令选项
为简洁起见省略):
To expand on Trevor's answer, you can push a single tag or all of your
tags at once.
Push a Single Tag
This is a summary of the relevant documentation that explains this (some
command options omitted for brevity):
Push All of Your Tags at Once
Here is a summary of the relevant documentation (some command options
omitted for brevity):
在当前分支中添加标签。如果您想为您的 master 创建标签,请首先签出 master。
检查它是否已创建
推送到您的远程源
Add a tag in your current branch. If you want to create the tag for your master, first check out to master.
Check if it's created or not
Push in your remote origin
您可以通过简单的 git push --tags 命令推送所有本地标签。
You can push all local tags by simply
git push --tags
command.标签不会通过 git push 命令发送到远程存储库。我们需要使用以下命令将这些标签显式发送到远程服务器:
我们可以使用以下命令一次性推送所有标签:
以下是有关 git 标签的完整详细信息的一些资源:
http://www.cubearticle.com/articles/more/git/git-tag
http://wptheming.com/2011/04/add-remove-github-tags
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:
We can push all the tags at once by using the below command:
Here are some resources for complete details on git tagging:
http://www.cubearticle.com/articles/more/git/git-tag
http://wptheming.com/2011/04/add-remove-github-tags
您可以像这样推送标签
git push --tags
You can push the tags like this
git push --tags
运行此命令将
mytag
推送到您的 git 源(例如:GitHub 或 GitLab)最好使用如上所示的完整“refspec”(字面意思
refs/tags/mytag
)以防万一mytag
实际上是v1.0.0
并且不明确(例如:因为有一个分支也名为v1.0.0
)。Run this to push
mytag
to your git origin (eg: GitHub or GitLab)It's better to use the full "refspec" as shown above (literally
refs/tags/mytag
) just in-casemytag
is actuallyv1.0.0
and is ambiguous (eg: because there's a branch also namedv1.0.0
).我正在使用 git pushtag以确保我正在推送标签。我使用它的方式如下:
git push origin tag v1.0.1
。此模式基于文档 (man git-push
):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
):将标签推送到远程
从远程获取所有标签
push tag to remote
fetch all tags from remote
我做了这样的事情:
I did something like this :
就我而言,我使用的是 Git 版本
2.30.0
我尝试了--follow-tags
和--tags
,但它们都没有无法将所有标签推送到远程存储库。我最终使用:因此,对于那些正在寻找一种将所有标签(连同主标签)推送到远程存储库的人,您只需添加以下
+refs/remotes/ origin/tags/*:refs/tags/*
到您的push
命令。所以你的命令应该是这样的:
它将成功地在远程存储库中创建所有标签。
In my case I am using Git version
2.30.0
I tried both--follow-tags
and--tags
, but both of them didn't work to push all the tags to the remote repo. I ended up using:So for those who are looking for a way to push all the tags (along with master) to a remote repo, you can just add the following
+refs/remotes/origin/tags/*:refs/tags/*
to yourpush
command.So your command should be something like this:
It will successfully create all your tags in the remote repo.