美文网首页
git-learn(3)

git-learn(3)

作者: 琉璃_xin | 来源:发表于2019-04-30 19:05 被阅读0次

    原作者文章地址:https://git-scm.com/book/zh/v2

    标签

    1. 轻量标签
      一个特定提交的引用
    $ git tag v0.1
    
    $ git tag
    v0.1
    
    1. 附注标签
      附注标签是存储在 Git 数据库中的一个完整对象。 它们是可以被校验的
    $ git tag -a v0.2 -m 'tag0.2'
    
    $ git tag
    v0.1
    v0.2
    
    1. 补标签
    $ git log --stat
    commit 8727432562429ed56a7c73c40ea6a19a7541e037 (HEAD -> master, tag: v0.2, tag: v0.1, git-test/master)
    Author: dongwudi <550293874@qq.com>
    Date:   Tue Apr 30 16:38:19 2019 +0800
    
        rm txt
    
     a.txt   | 1 -
     add.txt | 1 -
     b.txt   | 2 +-
     3 files changed, 1 insertion(+), 3 deletions(-)
    
    commit c70394a33401ecc6459c6c26c512b0e6245d22b0
    Author: dongwudi <550293874@qq.com>
    Date:   Tue Apr 30 16:26:54 2019 +0800
    
        first commit
    
     .gitignore | 2 ++
     a.txt      | 1 +
     add.txt    | 1 +
     b.txt      | 1 +
     readme.md  | 1 +
     5 files changed, 6 insertions(+)
    

    如果想给c70394a33401ecc6459c6c26c512b0e6245d22b0补一个标签

    $ git tag -a v0.3 -m 'tagv0.3' c70394a3
    

    打印后就看到已经添加了tagv0.3

    $ git log --stat
    commit 8727432562429ed56a7c73c40ea6a19a7541e037 (HEAD -> master, tag: v0.2, tag: v0.1, git-test/master)
    Author: dongwudi <550293874@qq.com>
    Date:   Tue Apr 30 16:38:19 2019 +0800
    
        rm txt
    
     a.txt   | 1 -
     add.txt | 1 -
     b.txt   | 2 +-
     3 files changed, 1 insertion(+), 3 deletions(-)
    
    commit c70394a33401ecc6459c6c26c512b0e6245d22b0 (tag: v0.3)
    Author: dongwudi <550293874@qq.com>
    Date:   Tue Apr 30 16:26:54 2019 +0800
    
        first commit
    
     .gitignore | 2 ++
     a.txt      | 1 +
     add.txt    | 1 +
     b.txt      | 1 +
     readme.md  | 1 +
     5 files changed, 6 insertions(+)
    
    1. 共享标签
      默认情况git push 命令不会推送标签到git远程仓库。可以使用git push <remote> [tagname] 显式推送
    $ git push git-test v0.1
    Total 0 (delta 0), reused 0 (delta 0)
    To https://github.com/dongwudi/gittest.git
     * [new tag]         v0.1 -> v0.1
    

    也可以使用git push <remote> --tags一次性推送所有不在远程仓库上的标签。

    $ git push git-test --tags
    Enumerating objects: 3, done.
    Counting objects: 100% (3/3), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 313 bytes | 156.00 KiB/s, done.
    Total 3 (delta 1), reused 0 (delta 0)
    remote: Resolving deltas: 100% (1/1), done.
    To https://github.com/dongwudi/gittest.git
     * [new tag]         v0.2 -> v0.2
     * [new tag]         v0.3 -> v0.3
     * [new tag]         v0.4 -> v0.4
    

    5.删除标签

    $ git tag -d v0.1
    Deleted tag 'v0.1' (was 8727432)
    

    上述命令并不会从远程仓库中移除这个标签,你必须使用 git push <remote> :refs/tags/<tagname> 来更新你的远程仓库

    $ git push git-test :refs/tags/v0.1
    To https://github.com/dongwudi/gittest.git
     - [deleted]         v0.1
    

    相关文章

      网友评论

          本文标题:git-learn(3)

          本文链接:https://www.haomeiwen.com/subject/rtavnqtx.html