标签管理

tag 是一个让人容易记住的有意义的名字,它跟某个commit绑在一起。

创建标签

1. 切换到需要打标签的分支上

2. 创建一个标签

  • 给当前最新提交的 commit 打一个标签

      git tag v1.0
    
  • 给历史上某一个 commit 打标签

    1. 根据日志找到需要打标签的 commit 号

       git log --pretty=oneline --abbrev-commit
      
    2. 给这个 commit 打标签

       git tag v0.9 6224937
      
  • 创建带有说明的标签,用-a指定标签名,-m指定说明文字:

      $ git tag -a v0.1 -m "version 0.1 released" 3628164
    

    查看标签

  • 查看所有标签:

     git tag
    

    注意:标签不是按时间顺序列出,而是按字母排序的

  • 查看某一标签的详情:

     git show v0.9
    
     $ git show v0.9
    commit 622493706ab447b6bb37e4e2a2f276a20fed2ab4
    Author: Michael Liao <[email protected]>
    Date:   Thu Aug 22 11:22:08 2013 +0800
    
     add merge
    ...
    

推送标签到远程

  1. 推送某一标签到远程

     git push origin <tagname>
    
  2. 推送全部尚未推送到远程

     $ git push origin --tags
    

删除标签

  1. 本地删除标签
     $ git tag -d v0.1
    
  2. 删除已经推送到远程的标签
    1. 先从本地删除 (同 1)
    2. 再从远程删除
       git push origin :refs/tags/v0.9
      

重命名标签

有两种方式:

  1. 删除原tag,重新添加
  2. git tag -f 强制替换已存在的 tag 后,再删除原 tag
    $ git tag -f <new-tag> <old-tag>
    $ git tag -d <old-tag>
    

results matching ""

    No results matching ""