Issue
I want to extract the number of latest version of a Git repository. This what I've done so far:
#--- Checking out latest tag
printf "%bChecking out tag...%b\n" "${YELLOW}" "${GRAY}"
LATEST_TAG=$(git describe --tags)
printf "\nChecking out tag %b${LATEST_TAG}%b\n" "${YELLOW}" "${GRAY}"
git checkout -b V${LATEST_TAG%-*} ${LATEST_TAG}
My problem is that if git describe --tags
returns something like this 1.0.0-39-gf8f8306
I end up creating a branch V1.0.0-39
.
What I want is to create a branch named V1.0.0
.
Solution
It’s a bit of a secret,* but you can use --abbrev=0
:
git describe --tags --abbrev=0
*git help describe
mentions it, but you have to know where to look:
--abbrev=<n>
[…] An
<n>
of 0 will suppress long format, only showing the closest tag.
Answered By - Biffen Answer Checked By - Pedro (WPSolving Volunteer)