git的tags操作汇总

101 阅读1分钟

git tags 操作手册

1 -查看tag列表

  • git tag -l 列出所有tag

  • git ls-remote --tags <remote> 查询远程的tags

    git ls-remote --tags
    
  • git show <tagname> 显示指定tag的详细信息

    git show v1.0.0
    

2 -从远程拉取tags

  • git pull <remote> --tags 合并远程的所有tags到本地

    git pull origin --tags
    
  • git pull <remote> --tags 合并远程的指定tags到本地

    git pull origin --tags v1.0.0
    
  • git fetch <remote> --prune从远程拉取所有信息

    git fetch --prune
    
  • git fetch <remote> --tags 从远程拉取所有tags

    git fetch --tags
    
  • git fetch <remote> --tags <tagname> 从远程拉取指定tags

    git fetch --tags v1.0.0
    

3 -创建tag

  • git tag <tagname> 创建轻量tag(无-m标注信息)

  • git tag -a <tagname> 创建含注解的tag

4 -推送tag到远程服务器

  • git push <remote> --tags 推送所有本地tag到远程

    git push origin --tags
    
  • git push <remote> --tags <tagname> 推送指定本地tag到远程

    git push origin v1.0.0
    git push origin --tags v1.0.0
    

5 -删除tag

  • git tag -d 删除本地指定tag

    git push -d v1.0.0
    
  • git push :refs/tags/ 删除远程tag版本

    git push origin :refs/tags/v1.0.0
    

6 -额外操作

  • git branch -a --contains <tagname> 看看哪个分支包含这个 tag/commit

  • git tag -l <tagname> 列出符合条件的tag(筛选作用),例如 v1.*

    git tag -l "*v1.*"  找到v1.所有的tags