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

后端 未结 7 2154
天命终不由人
天命终不由人 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:18

    I ended up writing a simple shell script to simplify this task.

    #!/usr/bin/env bash
    
    TAGS=$(git tag)
    CODE=$?
    
    if [ $CODE = 0 ]; then
        echo "$TAGS" | sort -V
    fi
    
    exit $CODE
    

    I saved that as git-tags in my $PATH and run git tags whenever I need to list tags.

提交回复
热议问题