How do you push a Git tag to a branch using a refspec?

后端 未结 4 1551
迷失自我
迷失自我 2020-12-07 06:49

I want to force push, for example, my tag 1.0.0 to my remote master branch.

I\'m now doing the following:

git push producti         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 07:26

    It is probably failing because 1.0.0 is an annotated tag. Perhaps you saw the following error message:

    error: Trying to write non-commit object to branch refs/heads/master

    Annotated tags have their own distinct type of object that points to the tagged commit object. Branches can not usefully point to tag objects, only commit objects. You need to “peel” the annotated tag back to commit object and push that instead.

    git push production +1.0.0^{commit}:master
    git push production +1.0.0~0:master          # shorthand
    

    There is another syntax that would also work in this case, but it means something slightly different if the tag object points to something other than a commit (or a tag object that points to (a tag object that points to a …) a commit).

    git push production +1.0.0^{}:master
    

    These tag peeling syntaxes are described in git-rev-parse(1) under Specifying Revisions.

提交回复
热议问题