首页 文章

如何使用Git将标签推送到远程存储库?

提问于
浏览
1711

我已经将一个远程Git存储库克隆到了我的笔记本电脑,然后我想添加一个标签,所以我跑了

git tag mytag master

当我在笔记本电脑上运行 git tag 时,会显示标签 mytag . 然后我想将它推送到远程存储库,所以我在所有客户端上都有这个标记,所以我运行了 git push 但是我收到了消息:

一切都是最新的

如果我转到桌面并运行 git pull 然后 git tag 则不会显示任何标签 .

我还尝试对项目中的文件进行微小更改,然后将其推送到服务器 . 之后,我可以将更改从服务器拉到我的台式计算机,但在台式计算机上运行 git tag 时仍然没有标记 .

如何将我的标签推送到远程存储库,以便所有客户端计算机都可以看到它?

10 回答

  • 235

    我正在使用 git push <remote-name> tag <tag-name> 以确保我正在推送标签 . 我用它像: git push origin tag v1.0.1 . 此模式基于文档( man git-push ):

    OPTIONS
       ...
       <refspec>...
           ...
           tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>.
    
  • 4

    要推送 single 标记:

    git push origin <tag_name>
    

    并且以下命令应该推送 all 标签(不推荐):

    git push --tags
    
  • 17

    Please do not use it, if you are only looking for a command because the main intention of this solution is to introduce you a way of solutions !

    为了让生活更轻松 - 我写了一个脚本git-cheat-sheet,其中包含一些有用的命令,包括以下内容:

    ./git_commands.sh -push_tag TAG_NAME

  • -1

    要推送特定的,一个标签执行以下 git push origin tag_name

  • 82

    你可以推这样的标签 git push --tags

  • -7

    您只需 git push --tags 命令即可推送本地标签 .

    $ git tag                         # see tag lists
    $ git push origin <tag-name>      # push a single tag
    $ git push --tags                 # push all local tags
    
  • 2790

    git push --follow-tags

    这是Git 1.8.3中引入的理智选择:

    git push --follow-tags
    

    它推送两个提交,只推送两个标签:

    • 注释
      _999_来自推送提交的可达(祖先)

    这是理智的,因为:

    出于这些原因,应该避免 --tags .

    Git 2.4 has added push.followTags 选项默认打开该标志,您可以设置:

    git config --global push.followTags true
    
  • 42

    要扩展Trevor's answer,您可以一次性推送单个标签或所有标签 .

    推送单个标签

    git push <remote> <tag>
    

    这是relevant documentation的摘要,解释了这一点(为简洁起见省略了一些命令选项):

    git push [[<repository> [<refspec> ...]]

    <的Refspec> ...
    <refspec>参数的格式是......源ref <src>,后跟冒号:,后跟目标ref <dst> ... <dst>告诉远程端哪个ref用这个push更新...如果:<dst>被省略,与<src>相同的引用将被更新... tag <tag>表示与refs / tags / <tag>相同:refs / tags / <tag> .

    一次推送所有标签

    git push --tags <remote>
    # Or
    git push <remote> --tags
    

    以下是relevant documentation的摘要(为简洁起见省略了一些命令选项):

    git push [--all | --mirror | --tags] [<repository> [<refspec> ...]]

    --tags
    除了在命令行中明确列出的refspec之外,还会推送refs / tags下的所有引用 .

  • 42

    git push命令不会将标记发送到远程存储库 . 我们需要使用以下命令将这些标记显式发送到远程服务器:

    git push origin <tagname>
    

    我们可以使用以下命令一次推送所有标签:

    git push origin --tags
    

    以下是有关git标记的完整详细信息的一些资源:

    http://www.cubearticle.com/articles/more/git/git-tag

    http://wptheming.com/2011/04/add-remove-github-tags

  • 745

    如果您在分公司工作:

    git push --tags origin branch_name
    

相关问题