How to sort git tags by version string order of form rc-X.Y.Z.W?

后端 未结 7 2151
天命终不由人
天命终不由人 2020-11-28 03:44

When I enter a command:

git tag -l

I get such results:

rc-0.9.0.0
rc-0.9.0.1
rc-0.9.0.10
rc-0.9.0.11
rc-0.9.0.12
rc-0.9.0.2         


        
相关标签:
7条回答
  • 2020-11-28 04:41

    Combining the answers already here:

    Local repository

    git -c 'versionsort.suffix=-' tag --list --sort=-v:refname
    
    • suffix=- will prevent 2.0-rc coming "after" 2.0
    • --sort=- will put the highest version number at the top.

    Remote repository

    git -c 'versionsort.suffix=-' ls-remote -t --exit-code --refs --sort=-v:refname "$repo_url" \
        | sed -E 's/^[[:xdigit:]]+[[:space:]]+refs\/tags\/(.+)/\1/g'
    

    The advantage of this is that no objects are downloaded from the remote.

    For more info see this answer.

    0 讨论(0)
提交回复
热议问题