Tag a git commit with a “tag” tag

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-05 04:17:11

问题


I have used the following command to tag my HEAD with a tag named "tag":

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

But when I

git push origin tag

I get an error:

fatal: tag shorthand without < tag >

I don't get the same error for tag with different name. I suppose git treats this "tag" as its sub-command. Maybe it is not an often use case... but is it possible to push "tag" to a remote repo? I wouldn't like to push my other tags with

git push --tags

though!


回答1:


If you take a look at the git code (link below), we can see that during a push it is checking for keyword tag.

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

Short answer: Give the tag a meaningful name and do not use git keywords

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);
    }
}


来源:https://stackoverflow.com/questions/39508892/tag-a-git-commit-with-a-tag-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!