1

Given the following:

PS C:\Users\jhau\Downloads\Trainee\I\GIT\Main\TEST000.git> git tag     
V2.1  
V2.25         
V5.0.0.0   
V5.0.141.0  
V5.0.600.0  
V5.0.640.0

How can I write a command to obtain the latest version tag, e.g. V5.0.640.0. I've tried this but it does not give the desired output

PS C:\Users\jhau\Downloads\Trainee\I\GIT\Main\TEST000.git> git describe --tags --abbrev=0  
V5.0.0.0
stackprotector
  • 10,498
  • 4
  • 35
  • 64

1 Answers1

0

As you are using a custom definition of "latest" (V5.0.640.0 being latest, while V5.0.0.0 has been committed after V5.0.640.0), you are basically looking for a way to sort version numbers.

Be aware that git tags can be any strings, not just version numbers of a certain format. As you use a certain format, you can parse those version numbers, convert them to a version number type, sort them and get the largest value. This is how you can do it in PowerShell:

git tag | ForEach-Object {
    [PSCustomObject]@{
        'tag'     = $_
        'version' = [System.Version]($_ -ireplace 'v', '')
    }
} | Sort-Object -Property 'version' | Select-Object -Last 1 -ExpandProperty 'tag'
stackprotector
  • 10,498
  • 4
  • 35
  • 64