如何使用 refspec 将 Git 标签推送到分支?

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

How do you push a Git tag to a branch using a refspec?

gitgit-pushgit-tag

提问by Michael van Rooijen

I want to force push, for example, my tag 1.0.0to my remote masterbranch.

我想强制推送,例如,我的标签1.0.0到我的远程master分支。

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.0tag is pushed to the masterbranch on the remote repository.

我想强制推送,因为我只关心1.0.0标签内的代码被推送到master远程存储库上的分支。

What am I doing wrong?

我究竟做错了什么?

Update #1

更新 #1

When I SSH into my server where my Gitrepository is and execute git branch -l, I don't see the masterbranch listed either.

当我通过 SSH 连接到我的Git存储库所在的服务器并执行时git branch -l,我也没有看到master列出的分支。

Update #2

更新 #2

After running git tag -lfrom inside the remote Git repository, I see that masteris listed, meaning that when I ran the following:

git tag -l从远程 Git 存储库内部运行后,我看到master已列出,这意味着当我运行以下命令时:

git push production 1.0.0:master

It actually pushed the tag and created a tag namedmasterrather than a new branch.

它实际上推送了标签并创建了一个名为master而不是新分支的标签

I want to basically push the contentsof the tag 1.0.0into the masterbranch of the remote Git repository.

我想基本上将标签的内容1.0.0送到master远程 Git 存储库的分支中。

采纳答案by Chris Johnsen

It is probably failing because 1.0.0is an annotated tag. Perhaps you saw the following error message:

它可能失败了,因为它是1.0.0一个带注释的标签。也许您看到了以下错误消息:

error: Trying to write non-commit object to branch refs/heads/master

错误:试图将非提交对象写入分支 refs/heads/master

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.

带注释的标签有自己独特的对象类型,指向带标签的提交对象。分支不能有效地指向标记对象,只能提交对象。您需要将带注释的标签“剥离”回提交对象并推送它。

git push production +1.0.0^{commit}:master
git push production +1.0.0~0:master          # shorthand

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

还有另一种语法也适用于这种情况,但如果标记对象指向提交以外的其他内容(或指向(指向……的标记对象)提交的标记对象),则意味着稍有不同.

git push production +1.0.0^{}:master

These tag peeling syntaxes are described in git-rev-parse(1)under Specifying Revisions.

这些标签剥离语法在git-rev-parse(1)下的指定修订中进行了描述

回答by bstpierre

git push --tags production

回答by neoneye

I create the tag like this and then I push it to GitHub:

我像这样创建标签,然后将其推送到 GitHub:

git tag -a v1.1 -m "Version 1.1 is waiting for review"
git push --tags

Counting objects: 1, done.
Writing objects: 100% (1/1), 180 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To [email protected]:neoneye/triangle_draw.git
 * [new tag]         v1.1 -> v1.1

回答by koppor

For pushing a single tag: git push <reponame> <tagname>

对于推送单个标签: git push <reponame> <tagname>

For instance, git push production 1.0.0. Tags are not bound to branches, they are bound to commits.

例如,git push production 1.0.0。标签不绑定到分支,它们绑定到提交。

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 mastershould suffice.

当您希望在 master 分支中拥有标签的内容时,请在您的机器上本地执行此操作。我假设您继续在本地主分支中进行开发。那么只需要一个git push origin master就足够了。