Can I make git print x.y.z style tag names in a sensible order?

后端 未结 3 1910
感情败类
感情败类 2021-01-05 01:48

Consider this list of version numbers:

0.3.0
0.3.1
...
0.3.8
0.3.9
0.3.10
0.3.11

git tag would print them in the following ord

3条回答
  •  一生所求
    2021-01-05 02:44

    serv ~: echo -e "1.1.1\n1.3.2\n1.1.10\n1.1.2" | sort -n -t. -k1,1 -k2,2 -k3,3
    1.1.1
    1.1.2
    1.1.10
    1.3.2
    

    Breakdown of the sort options being used here:

    • -n - sort using numerical string order (thus 10 comes after 1)
    • -t. - use periods as field separators
    • -k1,1 define a sort key on the first field (and only the first field)
    • -k2,2 define a sort key on the second field (and only the second field)
    • -k3,3 define a sort key on the third field (and only the third field)

提交回复
热议问题