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

发布于 2024-09-29 13:41:33 字数 828 浏览 8 评论 0原文

例如,我想强制推送我的标签 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 技术交流群。

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

发布评论

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

评论(4

你爱我像她 2024-10-06 13:41:33
git push --tags production
git push --tags production
傲世九天 2024-10-06 13:41:33

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

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

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

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

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

git push production +1.0.0^{}:master

这些标签剥离语法在 git-rev-parse( 1) 指定修订版< /a>.

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

error: Trying to write non-commit object to branch 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.

撞了怀 2024-10-06 13:41:33

我像这样创建标签,然后将其推送到 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

I create the tag like this and then I push it to 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
与他有关 2024-10-06 13:41:33

对于推送单个标签: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.

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