Outputs a human-readable version string from the nearest tag.
Produce a human-readable name for any commit relative to the nearest reachable tag. Output: v1.2-7-g<sha> means '7 commits past v1.2, current commit <sha>'.
Describe walks history backward from a commit until it finds a tag, then formats <tag>-<count>-g<short-sha>. With --always, it falls back to a bare short SHA if no tag is reachable.
git describe [--all] [--tags] [--contains] [--abbrev=<n>] [<commit-ish>...]
git describe [--all] [--tags] [--contains] [--abbrev=<n>] --dirty[=<mark>] --broken[=<mark>]| Flag | What it does |
|---|---|
--tags | Use any tag, not just annotated. |
--always | Fall back to short SHA if no tag is reachable. |
--abbrev=<n> | Length of the short SHA component. |
--dirty[=<suffix>] | Append -dirty (or chosen suffix) if working tree has changes. |
--match <pattern> | Only consider tags matching <pattern> (e.g. v[0-9]*). |
./configure --version=$(git describe)).$ git describe
v1.2-7-g2a3b4c5$ git describe --dirty
v1.2-7-g2a3b4c5-dirty$ git describe --match 'v[0-9]*'v<semver> and you can use --match 'v[0-9]*' reliably.--dirty in build scripts so accidentally-modified workspaces produce distinguishable versions.describe errors if no tag is reachable. Use --always to fall back.--tags (annotated tags are considered by default).Hit each option, then Check answers. Score is recorded; Next is always open.