Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 786
nfm Avatar asked May 22 '11 22:05

nfm


2 Answers

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)
like image 189
Amber Avatar answered Sep 28 '22 08:09

Amber


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:

  • -V sort by version
like image 32
Seth Robertson Avatar answered Sep 28 '22 08:09

Seth Robertson