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