]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-describe.txt
Merge branch 'ob/t9001-indent-fix'
[thirdparty/git.git] / Documentation / git-describe.txt
CommitLineData
c06818e2
JH
1git-describe(1)
2===============
3
4NAME
5----
644eb60b 6git-describe - Give an object a human readable name based on an available ref
c06818e2
JH
7
8SYNOPSIS
9--------
c5b3e0f5 10[verse]
2bd07065 11'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] [<commit-ish>...]
9f67d2e8 12'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] --dirty[=<mark>]
644eb60b 13'git describe' <blob>
c06818e2
JH
14
15DESCRIPTION
16-----------
17The command finds the most recent tag that is reachable from a
b7893cde
IH
18commit. If the tag points to the commit, then only the tag is
19shown. Otherwise, it suffixes the tag name with the number of
20additional commits on top of the tagged object and the
55f6bce2
FE
21abbreviated object name of the most recent commit. The result
22is a "human-readable" object name which can also be used to
23identify the commit to other git commands.
c06818e2 24
7e425c4f
SP
25By default (without --all or --tags) `git describe` only shows
26annotated tags. For more information about creating annotated tags
27see the -a and -s options to linkgit:git-tag[1].
c06818e2 28
644eb60b
SB
29If the given object refers to a blob, it will be described
30as `<commit-ish>:<path>`, such that the blob can be found
31at `<path>` in the `<commit-ish>`, which itself describes the
32first commit in which this blob occurs in a reverse revision walk
33from HEAD.
34
c06818e2
JH
35OPTIONS
36-------
a8a5406a 37<commit-ish>...::
2bd07065 38 Commit-ish object names to describe. Defaults to HEAD if omitted.
c06818e2 39
9f67d2e8 40--dirty[=<mark>]::
b0176ce6
SB
41--broken[=<mark>]::
42 Describe the state of the working tree. When the working
43 tree matches HEAD, the output is the same as "git describe
44 HEAD". If the working tree has local modification "-dirty"
45 is appended to it. If a repository is corrupt and Git
46 cannot determine if there is local modification, Git will
47 error out, unless `--broken' is given, which appends
48 the suffix "-broken" instead.
9f67d2e8 49
c06818e2
JH
50--all::
51 Instead of using only the annotated tags, use any ref
831e61f8 52 found in `refs/` namespace. This option enables matching
29b9a66f 53 any known branch, remote-tracking branch, or lightweight tag.
c06818e2
JH
54
55--tags::
56 Instead of using only the annotated tags, use any tag
831e61f8 57 found in `refs/tags` namespace. This option enables matching
7e425c4f 58 a lightweight (non-annotated) tag.
c06818e2 59
23615708
SP
60--contains::
61 Instead of finding the tag that predates the commit, find
62 the tag that comes after the commit, and thus contains it.
63 Automatically implies --tags.
64
c06818e2 65--abbrev=<n>::
bfe35a61
AH
66 Instead of using the default number of hexadecimal digits (which
67 will vary according to the number of objects in the repository with
68 a default of 7) of the abbreviated object name, use <n> digits, or
69 as many digits as needed to form a unique object name. An <n> of 0
492cf3f7 70 will suppress long format, only showing the closest tag.
c06818e2 71
8713ab30
SP
72--candidates=<n>::
73 Instead of considering only the 10 most recent tags as
a8a5406a 74 candidates to describe the input commit-ish consider
8713ab30
SP
75 up to <n> candidates. Increasing <n> above 10 will take
76 slightly longer but may produce a more accurate result.
2c33f757
SP
77 An <n> of 0 will cause only exact matches to be output.
78
79--exact-match::
80 Only output exact matches (a tag directly references the
81 supplied commit). This is a synonym for --candidates=0.
8713ab30
SP
82
83--debug::
84 Verbosely display information about the searching strategy
85 being employed to standard error. The tag name will still
86 be printed to standard out.
c06818e2 87
518120e3
SB
88--long::
89 Always output the long format (the tag, the number of commits
90 and the abbreviated commit name) even when it matches a tag.
91 This is useful when you want to see parts of the commit object name
92 in "describe" output, even when the commit in question happens to be
93 a tagged version. Instead of just emitting the tag name, it will
492cf3f7
GA
94 describe such a commit as v1.2-0-gdeadbee (0th commit since tag v1.2
95 that points at object deadbee....).
518120e3 96
30ffa603 97--match <pattern>::
52291497 98 Only consider tags matching the given `glob(7)` pattern,
6d68b2ab
MK
99 excluding the "refs/tags/" prefix. If used with `--all`, it also
100 considers local branches and remote-tracking references matching the
101 pattern, excluding respectively "refs/heads/" and "refs/remotes/"
102 prefix; references of other types are never considered. If given
103 multiple times, a list of patterns will be accumulated, and tags
104 matching any of the patterns will be considered. Use `--no-match` to
105 clear and reset the list of patterns.
30ffa603 106
77d21f29
JK
107--exclude <pattern>::
108 Do not consider tags matching the given `glob(7)` pattern, excluding
6d68b2ab
MK
109 the "refs/tags/" prefix. If used with `--all`, it also does not consider
110 local branches and remote-tracking references matching the pattern,
111 excluding respectively "refs/heads/" and "refs/remotes/" prefix;
112 references of other types are never considered. If given multiple times,
113 a list of patterns will be accumulated and tags matching any of the
114 patterns will be excluded. When combined with --match a tag will be
115 considered when it matches at least one --match pattern and does not
77d21f29
JK
116 match any of the --exclude patterns. Use `--no-exclude` to clear and
117 reset the list of patterns.
118
a3800f66
SB
119--always::
120 Show uniquely abbreviated commit object as fallback.
121
e00dd1e9
MC
122--first-parent::
123 Follow only the first parent commit upon seeing a merge commit.
124 This is useful when you wish to not match tags on branches merged
125 in the history of the target commit.
126
c06818e2
JH
127EXAMPLES
128--------
129
130With something like git.git current tree, I get:
131
b1889c36 132 [torvalds@g5 git]$ git describe parent
1891261e 133 v1.0.4-14-g2414721
c06818e2
JH
134
135i.e. the current head of my "parent" branch is based on v1.0.4,
323b9db8 136but since it has a few commits on top of that,
1891261e
JH
137describe has added the number of additional commits ("14") and
138an abbreviated object name for the commit itself ("2414721")
139at the end.
140
141The number of additional commits is the number
142of commits which would be displayed by "git log v1.0.4..parent".
548afb0d 143The hash suffix is "-g" + an unambiguous abbreviation for the tip commit
bfe35a61
AH
144of parent (which was `2414721b194453f058079d897d13c4e377f92dc6`). The
145length of the abbreviation scales as the repository grows, using the
146approximate number of objects in the repository and a bit of math
147around the birthday paradox, and defaults to a minimum of 7.
846b8f68
MH
148The "g" prefix stands for "git" and is used to allow describing the version of
149a software depending on the SCM the software is managed with. This is useful
150in an environment where people may use different SCMs.
c06818e2 151
0b444cdb 152Doing a 'git describe' on a tag-name will just show the tag name:
c06818e2 153
b1889c36 154 [torvalds@g5 git]$ git describe v1.0.4
c06818e2
JH
155 v1.0.4
156
157With --all, the command can use branch heads as references, so
158the output shows the reference path as well:
159
160 [torvalds@g5 git]$ git describe --all --abbrev=4 v1.0.5^2
1891261e 161 tags/v1.0.0-21-g975b
c06818e2 162
492cf3f7 163 [torvalds@g5 git]$ git describe --all --abbrev=4 HEAD^
1891261e
JH
164 heads/lt/describe-7-g975b
165
166With --abbrev set to 0, the command can be used to find the
167closest tagname without any suffix:
168
169 [torvalds@g5 git]$ git describe --abbrev=0 v1.0.5^2
170 tags/v1.0.0
c06818e2 171
492cf3f7 172Note that the suffix you get if you type these commands today may be
0a565de4 173longer than what Linus saw above when he ran these commands, as your
2de9b711 174Git repository may have new commits whose object names begin with
492cf3f7
GA
175975b that did not exist back then, and "-g975b" suffix alone may not
176be sufficient to disambiguate these commits.
177
178
8713ab30
SP
179SEARCH STRATEGY
180---------------
181
a8a5406a 182For each commit-ish supplied, 'git describe' will first look for
8713ab30
SP
183a tag which tags exactly that commit. Annotated tags will always
184be preferred over lightweight tags, and tags with newer dates will
185always be preferred over tags with older dates. If an exact match
186is found, its name will be output and searching will stop.
187
0b444cdb 188If an exact match was not found, 'git describe' will walk back
8713ab30
SP
189through the commit history to locate an ancestor commit which
190has been tagged. The ancestor's tag will be output along with an
bcf9626a 191abbreviation of the input commit-ish's SHA-1. If `--first-parent` was
e00dd1e9
MC
192specified then the walk will only consider the first parent of each
193commit.
8713ab30
SP
194
195If multiple tags were found during the walk then the tag which
a8a5406a 196has the fewest commits different from the input commit-ish will be
8713ab30 197selected and output. Here fewest commits different is defined as
483bc4f0 198the number of commits which would be shown by `git log tag..input`
8713ab30
SP
199will be the smallest number of commits possible.
200
644eb60b
SB
201BUGS
202----
203
204Tree objects as well as tag objects not pointing at commits, cannot be described.
205When describing blobs, the lightweight tags pointing at blobs are ignored,
548afb0d 206but the blob is still described as <commit-ish>:<path> despite the lightweight
644eb60b
SB
207tag being favorable.
208
c06818e2
JH
209GIT
210---
9e1f0a85 211Part of the linkgit:git[1] suite