git describe
Generate a human-readable name for the current commit
Practical Example
git describe --tags # v1.0.0-5-gabc1234 (5 commits after v1.0.0, hash abc1234) git describe --dirty # v1.0.0-dirty (uncommitted changes exist)
Command Overview & How It Works
Produces a string that combines the nearest annotated tag, the number of commits since that tag, and the abbreviated commit hash — for example, v1.0.0-5-gabc1234. This is the standard command for generating version strings in build systems and release artifacts. The format breaks down as: the closest tag name (v1.0.0), the number of additional commits since that tag (5), and the abbreviated commit hash prefixed with 'g' (gabc1234). Use git describe --tags to also consider lightweight tags, git describe --always to always show a result even without any tags, and git describe --dirty to append '-dirty' if the working directory has uncommitted changes. Many CI/CD pipelines use this command to embed version information into compiled binaries.
Practical Tips
- •Embed git describe --tags --always into build scripts to stamp binaries with a human-readable version.
- •Add --dirty so uncommitted changes are reflected in the version string.
- •The format <nearest-tag>-<commits-since>-g<hash> tells you exactly which commit a build came from.