interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / git-for-each-ref.adoc

478 lines · 16213 bytes Raw Blame History
1git-for-each-ref(1)
2===================
3
4NAME
5----
6git-for-each-ref - Output information on each ref
7
8SYNOPSIS
9--------
10[synopsis]
11git for-each-ref [--count=<count>] [--shell|--perl|--python|--tcl]
12 [(--sort=<key>)...] [--format=<format>]
13 [--include-root-refs] [--points-at=<object>]
14 [--merged[=<object>]] [--no-merged[=<object>]]
15 [--contains[=<object>]] [--no-contains[=<object>]]
16 [(--exclude=<pattern>)...] [--start-after=<marker>]
17 [ --stdin | (<pattern>...)]
18
19DESCRIPTION
20-----------
21
22Iterate over all refs that match _<pattern>_ and show them
23according to the given _<format>_, after sorting them according
24to the given set of _<key>_. If _<count>_ is given, stop after
25showing that many refs. The interpolated values in _<format>_
26can optionally be quoted as string literals in the specified
27host language allowing their direct evaluation in that language.
28
29OPTIONS
30-------
31include::for-each-ref-options.adoc[]
32
33FIELD NAMES
34-----------
35
36Various values from structured fields in referenced objects can
37be used to interpolate into the resulting output, or as sort
38keys.
39
40For all objects, the following names can be used:
41
42`refname`::
43 The name of the ref (the part after `$GIT_DIR/`).
44 For a non-ambiguous short name of the ref append `:short`.
45 The option `core.warnAmbiguousRefs` is used to select the strict
46 abbreviation mode. If `lstrip=<n>` (`rstrip=<n>`) is appended, strip _<n>_
47 slash-separated path components from the front (back) of the refname
48 (e.g. `%(refname:lstrip=2)` turns `refs/tags/foo` into `foo` and
49 `%(refname:rstrip=2)` turns `refs/tags/foo` into `refs`).
50 If _<n>_ is a negative number, strip as many path components as
51 necessary from the specified end to leave `-<n>` path components
52 (e.g. `%(refname:lstrip=-2)` turns
53 `refs/tags/foo` into `tags/foo` and `%(refname:rstrip=-1)`
54 turns `refs/tags/foo` into `refs`). When the ref does not have
55 enough components, the result becomes an empty string if
56 stripping with positive _<n>_, or it becomes the full refname if
57 stripping with negative _<N>_. Neither is an error.
58+
59`strip` can be used as a synonym to `lstrip`.
60
61`objecttype`::
62 The type of the object (`blob`, `tree`, `commit`, `tag`).
63
64`objectsize`::
65 The size of the object (the same as 'git cat-file -s' reports).
66 Append `:disk` to get the size, in bytes, that the object takes up on
67 disk. See the note about on-disk sizes in the
68 <<CAVEATS,'CAVEATS'>> section below.
69`objectname`::
70 The object name (aka SHA-1).
71 For a non-ambiguous abbreviation of the object name append `:short`.
72 For an abbreviation of the object name with desired length append
73 `:short=<length>`, where the minimum length is `MINIMUM_ABBREV`. The
74 length may be exceeded to ensure unique object names.
75`deltabase`::
76 This expands to the object name of the delta base for the
77 given object, if it is stored as a delta. Otherwise it
78 expands to the null object name (all zeroes).
79
80`upstream`::
81 The name of a local ref which can be considered ``upstream''
82 from the displayed ref. Respects `:short`, `:lstrip` and
83 `:rstrip` in the same way as `refname` above. Additionally
84 respects `:track` to show "[ahead N, behind M]" and
85 `:trackshort` to show the terse version: ">" (ahead), "<"
86 (behind), "<>" (ahead and behind), or "=" (in sync). `:track`
87 also prints "[gone]" whenever unknown upstream ref is
88 encountered. Append `:track,nobracket` to show tracking
89 information without brackets (i.e "ahead N, behind M").
90+
91For any remote-tracking branch `%(upstream)`, `%(upstream:remotename)`
92and `%(upstream:remoteref)` refer to the name of the remote and the
93name of the tracked remote ref, respectively. In other words, the
94remote-tracking branch can be updated explicitly and individually by
95using the refspec `%(upstream:remoteref):%(upstream)` to fetch from
96`%(upstream:remotename)`.
97+
98Has no effect if the ref does not have tracking information associated
99with it. All the options apart from `nobracket` are mutually exclusive,
100but if used together the last option is selected.
101
102`push`::
103 The name of a local ref which represents the `@{push}`
104 location for the displayed ref. Respects `:short`, `:lstrip`,
105 `:rstrip`, `:track`, `:trackshort`, `:remotename`, and `:remoteref`
106 options as `upstream` does. Produces an empty string if no `@{push}`
107 ref is configured.
108
109`HEAD`::
110 `*` if `HEAD` matches current ref (the checked out branch), ' '
111 otherwise.
112
113`color`::
114 Change output color. Followed by `:<colorname>`, where color
115 names are described under Values in the "CONFIGURATION FILE"
116 section of linkgit:git-config[1]. For example,
117 `%(color:bold red)`.
118
119`align`::
120 Left-, middle-, or right-align the content between
121 `%(align:...)` and `%(end)`. The "`align:`" is followed by
122 `width=<width>` and `position=<position>` in any order
123 separated by a comma, where the _<position>_ is either `left`,
124 `right` or `middle`, default being `left` and _<width>_ is the total
125 length of the content with alignment. For brevity, the
126 "width=" and/or "position=" prefixes may be omitted, and bare
127 _<width>_ and _<position>_ used instead. For instance,
128 `%(align:<width>,<position>)`. If the contents length is more
129 than the width then no alignment is performed. If used with
130 `--quote` everything in between `%(align:...)` and `%(end)` is
131 quoted, but if nested then only the topmost level performs
132 quoting.
133
134`if`::
135 Used as `%(if)...%(then)...%(end)` or
136 `%(if)...%(then)...%(else)...%(end)`. If there is an atom with
137 value or string literal after the `%(if)` then everything after
138 the `%(then)` is printed, else if the `%(else)` atom is used, then
139 everything after %(else) is printed. We ignore space when
140 evaluating the string before `%(then)`, this is useful when we
141 use the `%(HEAD)` atom which prints either "`*`" or " " and we
142 want to apply the 'if' condition only on the `HEAD` ref.
143 Append "`:equals=<string>`" or "`:notequals=<string>`" to compare
144 the value between the `%(if:...)` and `%(then)` atoms with the
145 given string.
146
147`symref`::
148 The ref which the given symbolic ref refers to. If not a
149 symbolic ref, nothing is printed. Respects the `:short`,
150 `:lstrip` and `:rstrip` options in the same way as `refname`
151 above.
152
153`signature`::
154 The GPG signature of a commit.
155
156`signature:grade`::
157 Show
158`G`;; for a good (valid) signature
159`B`;; for a bad signature
160`U`;; for a good signature with unknown validity
161`X`;; for a good signature that has expired
162`Y`;; for a good signature made by an expired key
163`R`;; for a good signature made by a revoked key
164`E`;; if the signature cannot be checked (e.g. missing key)
165`N`;; for no signature.
166
167`signature:signer`::
168 The signer of the GPG signature of a commit.
169
170`signature:key`::
171 The key of the GPG signature of a commit.
172
173`signature:fingerprint`::
174 The fingerprint of the GPG signature of a commit.
175
176`signature:primarykeyfingerprint`::
177 The primary key fingerprint of the GPG signature of a commit.
178
179`signature:trustlevel`::
180 The trust level of the GPG signature of a commit. Possible
181 outputs are `ultimate`, `fully`, `marginal`, `never` and `undefined`.
182
183`worktreepath`::
184 The absolute path to the worktree in which the ref is checked
185 out, if it is checked out in any linked worktree. Empty string
186 otherwise.
187
188`ahead-behind:<commit-ish>`::
189 Two integers, separated by a space, demonstrating the number of
190 commits ahead and behind, respectively, when comparing the output
191 ref to the _<committish>_ specified in the format.
192
193`is-base:<commit-ish>`::
194 In at most one row, `(<commit-ish>)` will appear to indicate the ref
195 that is most likely the ref used as a starting point for the branch
196 that produced _<commit-ish>_. This choice is made using a heuristic:
197 choose the ref that minimizes the number of commits in the
198 first-parent history of _<commit-ish>_ and not in the first-parent
199 history of the ref.
200+
201For example, consider the following figure of first-parent histories of
202several refs:
203+
204----
205*--*--*--*--*--* refs/heads/A
206\
207 \
208 *--*--*--* refs/heads/B
209 \ \
210 \ \
211 * * refs/heads/C
212 \
213 \
214 *--* refs/heads/D
215----
216+
217Here, if `A`, `B`, and `C` are the filtered references, and the format
218string is `%(refname):%(is-base:D)`, then the output would be
219+
220----
221refs/heads/A:
222refs/heads/B:(D)
223refs/heads/C:
224----
225+
226This is because the first-parent history of `D` has its earliest
227intersection with the first-parent histories of the filtered refs at a
228common first-parent ancestor of `B` and `C` and ties are broken by the
229earliest ref in the sorted order.
230+
231Note that this token will not appear if the first-parent history of
232_<commit-ish>_ does not intersect the first-parent histories of the
233filtered refs.
234
235`describe[:<option>,...]`::
236 A human-readable name, like linkgit:git-describe[1];
237 empty string for undescribable commits. The `describe` string may
238 be followed by a colon and one or more comma-separated options.
239+
240--
241`tags=<bool-value>`;;
242 Instead of only considering annotated tags, consider
243 lightweight tags as well; see the corresponding option in
244 linkgit:git-describe[1] for details.
245`abbrev=<number>`;;
246 Use at least _<number>_ hexadecimal digits; see the corresponding
247 option in linkgit:git-describe[1] for details.
248`match=<pattern>`;;
249 Only consider tags matching the `glob`(7) _<pattern>_,
250 excluding the `refs/tags/` prefix; see the corresponding option
251 in linkgit:git-describe[1] for details.
252`exclude=<pattern>`;;
253 Do not consider tags matching the `glob`(7) _<pattern>_,
254 excluding the `refs/tags/` prefix; see the corresponding option
255 in linkgit:git-describe[1] for details.
256--
257
258In addition to the above, for commit and tag objects, the header
259field names (`tree`, `parent`, `object`, `type`, and `tag`) can
260be used to specify the value in the header field.
261Fields `tree` and `parent` can also be used with modifier `:short` and
262`:short=<length>` just like `objectname`.
263
264For commit and tag objects, the special `creatordate` and `creator`
265fields will correspond to the appropriate date or name-email-date tuple
266from the `committer` or `tagger` fields depending on the object type.
267These are intended for working on a mix of annotated and lightweight tags.
268
269For tag objects, a `fieldname` prefixed with an asterisk (`*`) expands to
270the `fieldname` value of the peeled object, rather than that of the tag
271object itself.
272
273Fields that have name-email-date tuple as its value (`author`,
274`committer`, and `tagger`) can be suffixed with `name`, `email`,
275and `date` to extract the named component. For email fields (`authoremail`,
276`committeremail` and `taggeremail`), `:trim` can be appended to get the email
277without angle brackets, and `:localpart` to get the part before the `@` symbol
278out of the trimmed email. In addition to these, the `:mailmap` option and the
279corresponding `:mailmap,trim` and `:mailmap,localpart` can be used (order does
280not matter) to get values of the name and email according to the .mailmap file
281or according to the file set in the mailmap.file or mailmap.blob configuration
282variable (see linkgit:gitmailmap[5]).
283
284The raw data in an object is `raw`.
285
286`raw:size`::
287 The raw data size of the object.
288
289Note that `--format=%(raw)` can not be used with `--python`, `--shell`, `--tcl`,
290because such language may not support arbitrary binary data in their string
291variable type.
292
293The message in a commit or a tag object is `contents`, from which
294`contents:<part>` can be used to extract various parts out of:
295
296`contents:size`::
297 The size in bytes of the commit or tag message.
298
299`contents:subject`::
300 The first paragraph of the message, which typically is a
301 single line, is taken as the "subject" of the commit or the
302 tag message.
303 Instead of `contents:subject`, field `subject` can also be used to
304 obtain same results. `:sanitize` can be appended to `subject` for
305 subject line suitable for filename.
306
307`contents:body`::
308 The remainder of the commit or the tag message that follows
309 the "subject".
310
311`contents:signature`::
312 The optional GPG signature of the tag.
313
314`contents:lines=<n>`::
315 The first _<n>_ lines of the message.
316
317Additionally, the trailers as interpreted by linkgit:git-interpret-trailers[1]
318are obtained as `trailers[:<option>,...]` (or by using the historical alias
319`contents:trailers[:<option>,...]`). For valid _<option>_ values see `trailers`
320section of linkgit:git-log[1].
321
322For sorting purposes, fields with numeric values sort in numeric order
323(`objectsize`, `authordate`, `committerdate`, `creatordate`, `taggerdate`).
324All other fields are used to sort in their byte-value order.
325
326There is also an option to sort by versions, this can be done by using
327the fieldname `version:refname` or its alias `v:refname`.
328
329In any case, a field name that refers to a field inapplicable to
330the object referred by the ref does not cause an error. It
331returns an empty string instead.
332
333As a special case for the date-type fields, you may specify a format for the
334date by adding `:` followed by date format name (see the values the `--date`
335option to linkgit:git-rev-list[1] takes). If this formatting is provided in
336a `--sort` key, references will be sorted according to the byte-value of the
337formatted string rather than the numeric value of the underlying timestamp.
338
339Some atoms like `%(align)` and `%(if)` always require a matching `%(end)`.
340We call them "opening atoms" and sometimes denote them as `%($open)`.
341
342When a scripting language specific quoting is in effect, everything
343between a top-level opening atom and its matching %(end) is evaluated
344according to the semantics of the opening atom and only its result
345from the top-level is quoted.
346
347
348EXAMPLES
349--------
350
351An example directly producing formatted text. Show the most recent
3523 tagged commits:
353
354------------
355#!/bin/sh
356
357git for-each-ref --count=3 --sort='-*authordate' \
358`--format='From: %(*authorname) %(*authoremail)
359Subject: %(*subject)
360Date: %(*authordate)
361Ref: %(*refname)
362
363%(*body)
364' 'refs/tags'
365------------
366
367
368A simple example showing the use of shell eval on the output,
369demonstrating the use of `--shell`. List the prefixes of all heads:
370
371------------
372#!/bin/sh
373
374git for-each-ref --shell --format="ref=%(refname)" refs/heads | \
375while read entry
376do
377 eval "$entry"
378 echo `dirname $ref`
379done
380------------
381
382
383A bit more elaborate report on tags, demonstrating that the format
384may be an entire script:
385
386------------
387#!/bin/sh
388
389fmt='
390 r=%(refname)
391 t=%(*objecttype)
392 T=${r#refs/tags/}
393
394 o=%(*objectname)
395 n=%(*authorname)
396 e=%(*authoremail)
397 s=%(*subject)
398 d=%(*authordate)
399 b=%(*body)
400
401 kind=Tag
402 if test "z$t" = z
403 then
404 # could be a lightweight tag
405 t=%(objecttype)
406 kind="Lightweight tag"
407 o=%(objectname)
408 n=%(authorname)
409 e=%(authoremail)
410 s=%(subject)
411 d=%(authordate)
412 b=%(body)
413 fi
414 echo "$kind $T points at a $t object $o"
415 if test "z$t" = zcommit
416 then
417 echo "The commit was authored by $n $e
418at $d, and titled
419
420 $s
421
422Its message reads as:
423"
424 echo "$b" | sed -e "s/^/ /"
425 echo
426 fi
427'
428
429eval=`git for-each-ref --shell --format="$fmt" \
430 --sort='*objecttype' \
431 --sort=-taggerdate \
432 refs/tags`
433eval "$eval"
434------------
435
436
437An example to show the usage of `%(if)...%(then)...%(else)...%(end)`.
438This prefixes the current branch with a star.
439
440------------
441git for-each-ref --format="%(if)%(HEAD)%(then)* %(else) %(end)%(refname:short)" refs/heads/
442------------
443
444
445An example to show the usage of `%(if)...%(then)...%(end)`.
446This prints the authorname, if present.
447
448------------
449git for-each-ref --format="%(refname)%(if)%(authorname)%(then) Authored by: %(authorname)%(end)"
450------------
451
452[[CAVEATS]]
453CAVEATS
454-------
455
456Note that the sizes of objects on disk are reported accurately, but care
457should be taken in drawing conclusions about which refs or objects are
458responsible for disk usage. The size of a packed non-delta object may be
459much larger than the size of objects which delta against it, but the
460choice of which object is the base and which is the delta is arbitrary
461and is subject to change during a repack.
462
463Note also that multiple copies of an object may be present in the object
464database; in this case, it is undefined which copy's size or delta base
465will be reported.
466
467NOTES
468-----
469
470include::ref-reachability-filters.adoc[]
471
472SEE ALSO
473--------
474linkgit:git-show-ref[1]
475
476GIT
477---
478Part of the linkgit:git[1] suite