Reputation: 8855
I know how to receive the latest git version by using git describe --tags --abbrev=0
. However in my special case I need the version ONE before.
If the latest version is v0.0.3
I need to get v0.0.2
for instance.
I tried to find a way to do so but my shell/git magic is weak.
Upvotes: 1
Views: 94
Reputation: 133600
With awk
along with your git
command could you please try following.
git describe --tags --abbrev=0 | awk 'BEGIN{FS=OFS="."} {$NF-=1} 1'
Explanation: Passing git
command's output to awk
command as an input. In awk
code BEGIN
section setting field separator and output field separator as .
for all lines. Then in main program deceasing 1
in last field of current line. 1
is one of the ways in awk
to print current line.
Upvotes: 2
Reputation: 5884
git describe --tags --abbrev=0 HEAD^
The parent of the HEAD commit is HEAD^. Using --abbrev=0
as you already were prevents the output of the sha as part of the description, so only printing the first found tag.
$ git log --oneline
63fbe99 (HEAD -> master, tag: v0.0.2) Add c
3de8c2c Add b
98b2cc4 (tag: v0.0.1) Add a
1fe3ea8 (tag: v0.0.0) Initial commit
$ git describe --tags --abbrev=0
v0.0.2
$ git describe --tags --abbrev=0 HEAD^
v0.0.1
Upvotes: 4