Git 常用命令

Git 常用命令

hb0730 110 2022-07-29

Git tag

排序

  1. 根据refname排序

    # 正序
    git tag --sort=v:refname
    # 倒序
    git tag --sort=-v:refname
    
    $ git tag --sort=v:refname
    1.0.9
    2.0.0
    2.0.7
    4.0.8
    5.0.1
    
  2. 通过describe获取最新的

    # 最新tag
    git describe --tags --abbrev=0
    # 上一个tag
    git describe --tags --abbrev=0 tags/tag^
    
    $ git describe --tags --abbrev=0
    v5.4.0
    
    $ git describe --tags --abbrev=0 tags/v5.4.0^
    5.3.8
    
  3. 通过creatordate排序

    # 正序,最近两个tag
    git tag -n --sort=creatordate --format="%(refname:strip=2)" | head -n 2
    # 倒序, 最近两tag
    git tag -n --sort=-creatordate --format="%(refname:strip=2)" | head -n 2
    
    $ git tag -n --sort=creatordate --format="%(refname:strip=2)" | head -n 2
    v1.0.0
    v1.0.5
    
    $ git tag -n --sort=-creatordate --format="%(refname:strip=2)" | head -n 2
    v5.4.0
    5.3.8