2016-09-15 212 views
0

我用下面的命令与一个名为“标签”标签来标记我的头承诺:标签一个git用“标签”标签

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

当我

git push origin tag 

我得到不过,一个错误:

fatal: tag shorthand without < tag >

我没有得到相同的错误标记与不同的名称。我想git把这个​​“标签”当作它的子命令。也许这不是一个经常使用的情况......但是可以将“标签”推送到远程回购?我不想推我的其他标签

git push --tags 

虽然!

+3

如果你混帐推的文档中查找(即做'混帐推--help'。并搜索标签)。你会看到'git push'有一个特定的关键字,你可以用它明确指定你可以用来推送标签。这个关键字就是'tag'(惊喜!)。所以,理论上你可以做'git push tag tag',第一个'tag'是关键字,第二个'tag'是标签名。但是,我同意下面的答案:命名标签'tag'是不可取的。 – Alderath

+0

我只尝试过“git push -tag tag”和“git push --tag tag”。 谢谢! :) – forestgril

回答

1

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

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