【问题标题】:Tag a git commit with a "tag" tag使用“tag”标签标记 git 提交
【发布时间】:2016-09-15 10:33:13
【问题描述】:

我已使用以下命令将我的 HEAD 标记为一个名为“tag”的标签:

git tag -a tag -m "comment on my tag"

但是当我

git push origin tag

我收到一个错误:

fatal:不带

的tag简写

对于具有不同名称的标签,我没有收到相同的错误。我想 git 把这个“标签”当作它的子命令。也许这不是一个经常使用的案例......但是否可以将“标签”推送到远程仓库?我不想用

推送我的其他标签
git push --tags

虽然!

【问题讨论】:

  • 如果您查看 git push 的文档(即执行 git push --help 并搜索标签)。您将看到git push 有一个特定的关键字,您可以使用它来明确指定您可以用于推送标签。这个关键字就是tag(惊喜!)。所以理论上你可以做git push tag tag,其中第一个tag是关键字,第二个tag是标签名称。但是,我同意下面的答案:命名标签tag 是不可取的。
  • 我只试过“git push -tag tag”和“git push --tag tag”。谢谢你! :)

标签: git tags push


【解决方案1】:

如果你看一下 git 代码(下面的链接),我们可以看到在 push 期间它正在检查关键字 tag

https://github.com/tnachen/git/blob/master/builtin/push.c

简答:给标签起一个有意义的名字,不要使用 git 关键字

static void set_refspecs(const char **refs, int nr)
{
    int i;
    for (i = 0; i < nr; i++) {
        const char *ref = refs[i];
        if (!strcmp("tag", ref)) {
            char *tag;
            int len;
            if (nr <= ++i)
                die("tag shorthand without <tag>");
            len = strlen(refs[i]) + 11;
            if (deleterefs) {
                tag = xmalloc(len+1);
                strcpy(tag, ":refs/tags/");
            } else {
                tag = xmalloc(len);
                strcpy(tag, "refs/tags/");
            }
            strcat(tag, refs[i]);
            ref = tag;
        } else if (deleterefs && !strchr(ref, ':')) {
            char *delref;
            int len = strlen(ref)+1;
            delref = xmalloc(len+1);
            strcpy(delref, ":");
            strcat(delref, ref);
            ref = delref;
        } else if (deleterefs)
            die("--delete only accepts plain target ref names");
        add_refspec(ref);
    }
}

【讨论】:

    【解决方案2】:

    这就是我所做的:

    • 标签分支创建了一个新分支
    • 切换到新分支
    • 将我的代码推送到远程仓库

    我后来删除了 tag 分支。

    希望有帮助!

    【讨论】:

    • 谢谢 :) 这似乎是一种解决方法,但有趣的是,这是可能的,而不是通常的方法! :)
    猜你喜欢
    • 2018-11-05
    • 1970-01-01
    • 2015-10-18
    • 2023-02-09
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 2013-07-28
    • 2015-12-06
    相关资源
    最近更新 更多