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 order:
0.3.0
0.3.1
0.3.10
0.3.11
0.3.2
...
I there any way to make git tag
print them in 'numeric' order as opposed to alphabetical order? Or a workaround - perhaps a program I can pipe the output through to order them how I want?
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)Easier solution:
serv ~: echo -e "1.1.1\n1.3.2\n1.1.10\n1.1.2" | sort -V
1.1.1
1.1.2
1.1.10
1.3.2
Breakdown of the sort
options being used here:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With