Home·Terminal commands

git describe

git

Usage

git describe [--tags] [--dirty]

Names the current commit from the nearest tag, as v1.2.0-5-gabc1234; it only sees annotated tags by default, so lightweight ones need --tags and a repository with no tag needs --always.

Common flags

FlagMeaning
--tagsuse lightweight tags too, not just annotated ones
--dirtyappend -dirty when the working tree has changes
--alwaysfall back to a bare hash when no tag is found
--longalways the full tag-count-hash form
--abbrev=<n>how many hash digits to print
--match <pattern>only consider matching tags

Examples

git describe --tags --dirty

prints something like v1.2.0-5-gabc1234-dirty

git describe --always

never fails, even in a repository with no tags

git describe --match "v*" --long

ignores tags that are not versions

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git describe do?

Names the current commit from the nearest tag, as v1.2.0-5-gabc1234; it only sees annotated tags by default, so lightweight ones need --tags and a repository with no tag needs --always.

Q. How do I type it?

git describe [--tags] [--dirty] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-describe