【问题标题】:Replace remote tag with Git用 Git 替换远程标签
【发布时间】:2013-12-03 06:46:36
【问题描述】:

我的“来源”存储库中有一些标签。然后我意识到我需要在其中一个标签上添加一些更改,然后将它们推送回我的存储库。 有没有一种方法可以一次性将现有标签推送到存储库,还是应该在之前删除标签?

【问题讨论】:

标签: git tags branch


【解决方案1】:

我不确定我是否理解您的问题,但听起来最简单的方法是删除标签,推送您的更改,然后重新添加标签...

【讨论】:

    【解决方案2】:

    这不应该是惯例,尽管您可以删除标签并将更改推送到远程仓库。

    git tag -d tag1
    git push origin :refs/tags/tag1
    

    【讨论】:

    • 还有git push --delete origin tag1。见here
    【解决方案3】:

    因此,如果您需要将 git 分支(例如:“master”)上的标签(例如:“v0.5”)移动到不同的提交,可能是较新的,那么您可以使用-f 选项到git tag

    -f
    --force
    
    Replace an existing tag with the given name (instead of failing)
    

    您可能希望将-f-a 结合使用来强制创建带注释的标签而不是未注释的标签。

    示例

    1. 在推送之前删除任何遥控器上的标签

      git push origin :refs/tags/<tagname>
      

      或者对于我们的示例:

      $ git push origin master :refs/tags/v0.5
      To git@github.com:org_name/repo_name.git
      - [deleted]         v0.5
      
    2. 替换标记以引用最近的提交(使用 -f 将保存为git tag -d &lt;tagname&gt; 本地标记删除步骤)。

      git tag -fa <tagname>
      

      或者对于我们的示例:

      $ git tag -fa "v0.5" -m "version 0.5"
      Updated tag 'v0.5' (was f55c93f)
      
    3. 将标签推送到远程源

      git push origin --tags
      

      或者对于我们的示例:

      $ git push origin master --tags
      Counting objects: 1, done.
      Writing objects: 100% (1/1), 196 bytes | 0 bytes/s, done.
      Total 1 (delta 0), reused 0 (delta 0)
      To git@github.com:org_name/repo_name.git
      * [new tag]         v0.5 -> v0.5
      

    【讨论】:

      【解决方案4】:

      假设newtag 是新标签,oldtag 是旧标签。只需这样做:

      # Create new tag that points to the same of old tag
      git tag newtag oldtag
      
      # Remove oldtag
      git tag -d oldtag
      
      # Remove oldtag in remote machine
      git push --delete origin oldtag
      
      # Propapate newtag to remote machine
      git push --tags
      

      【讨论】:

        猜你喜欢
        • 2012-01-06
        • 2016-07-24
        • 1970-01-01
        • 2015-10-19
        • 1970-01-01
        • 1970-01-01
        • 2011-07-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多