如何使用 refspec 将 Git 标签推送到分支?
例如,我想强制推送我的标签 1.0.0
到我的远程 master
分支。
我现在正在执行以下操作:
git push production +1.0.0:master
我想强制推送,因为我关心的是 1.0.0
中的代码标签被推送到远程存储库上的 master
分支。
我做错了什么?
更新 #1
当我通过 SSH 连接到我的 Git 存储库所在的服务器并执行 < code>gitbranch-l,我也没有看到列出的 master
分支。
更新 #2
从远程 Git 存储库中运行 git tag -l 后,我看到列出了 master ,这意味着当我运行以下命令时:
git push production 1.0.0:master
它实际上推送了标签并创建了一个名为master
的标签,而不是一个新分支。
我基本上想将标签 1.0.0
的 内容 推送到远程 Git 存储库的 master
分支。
I want to force push, for example, my tag 1.0.0
to my remote master
branch.
I'm now doing the following:
git push production +1.0.0:master
I want to force the push, because all I care about is that the code inside the 1.0.0
tag is pushed to the master
branch on the remote repository.
What am I doing wrong?
Update #1
When I SSH into my server where my Git repository is and execute git branch -l
, I don't see the master
branch listed either.
Update #2
After running git tag -l
from inside the remote Git repository, I see that master
is listed, meaning that when I ran the following:
git push production 1.0.0:master
It actually pushed the tag and created a tag named master
rather than a new branch.
I want to basically push the contents of the tag 1.0.0
into the master
branch of the remote Git repository.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它可能会失败,因为
1.0.0
是一个带注释的标签。也许您看到以下错误消息:带注释的标记有自己独特的对象类型,该对象指向带标记的提交对象。分支不能有效地指向标记对象,只能提交对象。您需要将带注释的标签“剥离”回提交对象并推送它。
还有另一种语法也适用于这种情况,但如果标记对象指向提交以外的其他内容(或指向(指向...的标记对象)提交的标记对象),则含义略有不同。 。
这些标签剥离语法在 git-rev-parse( 1) 指定修订版< /a>.
It is probably failing because
1.0.0
is an annotated tag. Perhaps you saw the following error message:Annotated tags have their own distinct type of object that points to the tagged commit object. Branches can not usefully point to tag objects, only commit objects. You need to “peel” the annotated tag back to commit object and push that instead.
There is another syntax that would also work in this case, but it means something slightly different if the tag object points to something other than a commit (or a tag object that points to (a tag object that points to a …) a commit).
These tag peeling syntaxes are described in git-rev-parse(1) under Specifying Revisions.
我像这样创建标签,然后将其推送到 GitHub:
I create the tag like this and then I push it to GitHub:
对于推送单个标签:
git push;
例如,
git Push Production 1.0.0
。标签不绑定到分支,它们绑定到提交。当您希望将标签的内容放在主分支中时,请在您的计算机上本地执行此操作。我假设您继续在本地主分支中进行开发。那么只需一个 git push origin master 就足够了。
For pushing a single tag:
git push <reponame> <tagname>
For instance,
git push production 1.0.0
. Tags are not bound to branches, they are bound to commits.When you want to have the tag's content in the master branch, do that locally on your machine. I would assume that you continued developing in your local master branch. Then just a
git push origin master
should suffice.