Listing Tags

Listing, Searching and Checking Out Tags

git tag -l takes a pattern (git tag -l 'v1.*') and a sort key, and git describe names any commit relative to the nearest tag:

Sorting tags as versions, and describing a commitShell
git tag -l --sort=-v:refname
git -c versionsort.suffix=-rc tag -l --sort=-v:refname
git describe --tags v1.0.0~1
Output
v1.1.0-rc.0
v1.1.0
v1.0.0
v0.9.0
v1.1.0
v1.1.0-rc.0
v1.0.0
v0.9.0
v0.9.0-6-ga2508da

v:refname compares numbers as numbers (newest first with -) but ranks v1.1.0-rc.0 above v1.1.0; versionsort.suffix=-rc, set once globally, fixes that. git tag --contains 3dfdfa3 answers "which releases include the escaping fix of Cherry-Picking?". v0.9.0-6-ga2508da reads "six commits after v0.9.0, at a2508da", a good build version between releases. Checking out a tag detaches HEAD, since a tag cannot move:

Checking out a release and returning to mainShell
git switch --detach v1.0.0
git switch -
Output
HEAD is now at 8211cbb Merge the npm run dev documentation
Previous HEAD position was 8211cbb Merge the npm run dev documentation
Switched to branch 'main'
Your branch is up to date with 'origin/main'.

git switch insists on --detach for a tag, while the older git checkout v1.0.0 detaches without being asked. Commits made on a detached HEAD belong to no branch, so to fix an old release, start a branch at its tag, git switch -c hotfix-1.0 v1.0.0 (Release and Hotfix Branches). git switch - returns to the previous branch.