2 .\" Title: git-for-each-ref
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.40.1.423.g2807bd2c10
10 .TH "GIT\-FOR\-EACH\-REF" "1" "04/25/2023" "Git 2\&.40\&.1\&.423\&.g2807bd" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 git-for-each-ref \- Output information on each ref
35 \fIgit for\-each\-ref\fR [\-\-count=<count>] [\-\-shell|\-\-perl|\-\-python|\-\-tcl]
36 [(\-\-sort=<key>)\&...] [\-\-format=<format>]
37 [ \-\-stdin | <pattern>\&... ]
38 [\-\-points\-at=<object>]
39 [\-\-merged[=<object>]] [\-\-no\-merged[=<object>]]
40 [\-\-contains[=<object>]] [\-\-no\-contains[=<object>]]
45 Iterate over all refs that match \fB<pattern>\fR and show them according to the given \fB<format>\fR, after sorting them according to the given set of \fB<key>\fR\&. If \fB<count>\fR is given, stop after showing that many refs\&. The interpolated values in \fB<format>\fR can optionally be quoted as string literals in the specified host language allowing their direct evaluation in that language\&.
50 If one or more patterns are given, only refs are shown that match against at least one pattern, either using fnmatch(3) or literally, in the latter case matching completely or from the beginning up to a slash\&.
57 is supplied, then the list of patterns is read from standard input instead of from the argument list\&.
62 By default the command shows all refs that match
63 \fB<pattern>\fR\&. This option makes it stop after showing that many refs\&.
68 A field name to sort on\&. Prefix
70 to sort in descending order of the value\&. When unspecified,
72 is used\&. You may use the \-\-sort=<key> option multiple times, in which case the last key becomes the primary key\&.
77 A string that interpolates
79 from a ref being shown and the object it points at\&. If
81 is prefixed with an asterisk (\fB*\fR) and the ref points at a tag object, use the value for the field in the object which the tag object refers to (instead of the field in the tag object)\&. When unspecified,
84 \fB%(objectname) SPC %(objecttype) TAB %(refname)\fR\&. It also interpolates
91 are hex digits interpolates to character with hex code
109 Respect any colors specified in the
119 is absent, behave as if
124 \-\-shell, \-\-perl, \-\-python, \-\-tcl
126 If given, strings that substitute
128 placeholders are quoted as string literals suitable for the specified host language\&. This is meant to produce a scriptlet that can directly be `eval`ed\&.
131 \-\-points\-at=<object>
133 Only list refs which points at the given object\&.
136 \-\-merged[=<object>]
138 Only list refs whose tips are reachable from the specified commit (HEAD if not specified)\&.
141 \-\-no\-merged[=<object>]
143 Only list refs whose tips are not reachable from the specified commit (HEAD if not specified)\&.
146 \-\-contains[=<object>]
148 Only list refs which contain the specified commit (HEAD if not specified)\&.
151 \-\-no\-contains[=<object>]
153 Only list refs which don\(cqt contain the specified commit (HEAD if not specified)\&.
158 Sorting and filtering refs are case insensitive\&.
163 Do not print a newline after formatted refs where the format expands to the empty string\&.
167 Various values from structured fields in referenced objects can be used to interpolate into the resulting output, or as sort keys\&.
169 For all objects, the following names can be used:
173 The name of the ref (the part after $GIT_DIR/)\&. For a non\-ambiguous short name of the ref append
174 \fB:short\fR\&. The option core\&.warnAmbiguousRefs is used to select the strict abbreviation mode\&. If
176 (\fBrstrip=<N>\fR) is appended, strips
178 slash\-separated path components from the front (back) of the refname (e\&.g\&.
179 \fB%(refname:lstrip=2)\fR
185 \fB%(refname:rstrip=2)\fR
191 is a negative number, strip as many path components as necessary from the specified end to leave
193 path components (e\&.g\&.
194 \fB%(refname:lstrip=\-2)\fR
200 \fB%(refname:rstrip=\-1)\fR
204 \fBrefs\fR)\&. When the ref does not have enough components, the result becomes an empty string if stripping with positive <N>, or it becomes the full refname if stripping with negative <N>\&. Neither is an error\&.
207 can be used as a synonym to
213 The type of the object (\fBblob\fR,
221 The size of the object (the same as
222 \fIgit cat\-file \-s\fR
225 to get the size, in bytes, that the object takes up on disk\&. See the note about on\-disk sizes in the
232 The object name (aka SHA\-1)\&. For a non\-ambiguous abbreviation of the object name append
233 \fB:short\fR\&. For an abbreviation of the object name with desired length append
234 \fB:short=<length>\fR, where the minimum length is MINIMUM_ABBREV\&. The length may be exceeded to ensure unique object names\&.
239 This expands to the object name of the delta base for the given object, if it is stored as a delta\&. Otherwise it expands to the null object name (all zeroes)\&.
244 The name of a local ref which can be considered \(lqupstream\(rq from the displayed ref\&. Respects
251 above\&. Additionally respects
253 to show "[ahead N, behind M]" and
255 to show the terse version: ">" (ahead), "<" (behind), "<>" (ahead and behind), or "=" (in sync)\&.
257 also prints "[gone]" whenever unknown upstream ref is encountered\&. Append
258 \fB:track,nobracket\fR
259 to show tracking information without brackets (i\&.e "ahead N, behind M")\&.
261 For any remote\-tracking branch
263 \fB%(upstream:remotename)\fR
265 \fB%(upstream:remoteref)\fR
266 refer to the name of the remote and the name of the tracked remote ref, respectively\&. In other words, the remote\-tracking branch can be updated explicitly and individually by using the refspec
267 \fB%(upstream:remoteref):%(upstream)\fR
269 \fB%(upstream:remotename)\fR\&.
271 Has no effect if the ref does not have tracking information associated with it\&. All the options apart from
273 are mutually exclusive, but if used together the last option is selected\&.
278 The name of a local ref which represents the
280 location for the displayed ref\&. Respects
286 \fB:remotename\fR, and
290 does\&. Produces an empty string if no
298 if HEAD matches current ref (the checked out branch), \*(Aq \*(Aq otherwise\&.
303 Change output color\&. Followed by
304 \fB:<colorname>\fR, where color names are described under Values in the "CONFIGURATION FILE" section of
305 \fBgit-config\fR(1)\&. For example,
306 \fB%(color:bold red)\fR\&.
311 Left\-, middle\-, or right\-align the content between %(align:\&...) and %(end)\&. The "align:" is followed by
314 \fBposition=<position>\fR
315 in any order separated by a comma, where the
317 is either left, right or middle, default being left and
319 is the total length of the content with alignment\&. For brevity, the "width=" and/or "position=" prefixes may be omitted, and bare <width> and <position> used instead\&. For instance,
320 \fB%(align:<width>,<position>)\fR\&. If the contents length is more than the width then no alignment is performed\&. If used with
322 everything in between %(align:\&...) and %(end) is quoted, but if nested then only the topmost level performs quoting\&.
327 Used as %(if)\&...%(then)\&...%(end) or %(if)\&...%(then)\&...%(else)\&...%(end)\&. If there is an atom with value or string literal after the %(if) then everything after the %(then) is printed, else if the %(else) atom is used, then everything after %(else) is printed\&. We ignore space when evaluating the string before %(then), this is useful when we use the %(HEAD) atom which prints either "*" or " " and we want to apply the
329 condition only on the
331 ref\&. Append ":equals=<string>" or ":notequals=<string>" to compare the value between the %(if:\&...) and %(then) atoms with the given string\&.
336 The ref which the given symbolic ref refers to\&. If not a symbolic ref, nothing is printed\&. Respects the
341 options in the same way as
348 The absolute path to the worktree in which the ref is checked out, if it is checked out in any linked worktree\&. Empty string otherwise\&.
351 ahead\-behind:<committish>
353 Two integers, separated by a space, demonstrating the number of commits ahead and behind, respectively, when comparing the output ref to the
355 specified in the format\&.
358 In addition to the above, for commit and tag objects, the header field names (\fBtree\fR, \fBparent\fR, \fBobject\fR, \fBtype\fR, and \fBtag\fR) can be used to specify the value in the header field\&. Fields \fBtree\fR and \fBparent\fR can also be used with modifier \fB:short\fR and \fB:short=<length>\fR just like \fBobjectname\fR\&.
360 For commit and tag objects, the special \fBcreatordate\fR and \fBcreator\fR fields will correspond to the appropriate date or name\-email\-date tuple from the \fBcommitter\fR or \fBtagger\fR fields depending on the object type\&. These are intended for working on a mix of annotated and lightweight tags\&.
362 Fields that have name\-email\-date tuple as its value (\fBauthor\fR, \fBcommitter\fR, and \fBtagger\fR) can be suffixed with \fBname\fR, \fBemail\fR, and \fBdate\fR to extract the named component\&. For email fields (\fBauthoremail\fR, \fBcommitteremail\fR and \fBtaggeremail\fR), \fB:trim\fR can be appended to get the email without angle brackets, and \fB:localpart\fR to get the part before the \fB@\fR symbol out of the trimmed email\&.
364 The raw data in an object is \fBraw\fR\&.
368 The raw data size of the object\&.
371 Note that \fB\-\-format=%(raw)\fR can not be used with \fB\-\-python\fR, \fB\-\-shell\fR, \fB\-\-tcl\fR, because such language may not support arbitrary binary data in their string variable type\&.
373 The message in a commit or a tag object is \fBcontents\fR, from which \fBcontents:<part>\fR can be used to extract various parts out of:
377 The size in bytes of the commit or tag message\&.
382 The first paragraph of the message, which typically is a single line, is taken as the "subject" of the commit or the tag message\&. Instead of
383 \fBcontents:subject\fR, field
385 can also be used to obtain same results\&.
389 for subject line suitable for filename\&.
394 The remainder of the commit or the tag message that follows the "subject"\&.
399 The optional GPG signature of the tag\&.
406 lines of the message\&.
409 Additionally, the trailers as interpreted by \fBgit-interpret-trailers\fR(1) are obtained as \fBtrailers[:options]\fR (or by using the historical alias \fBcontents:trailers[:options]\fR)\&. For valid [:option] values see \fBtrailers\fR section of \fBgit-log\fR(1)\&.
411 For sorting purposes, fields with numeric values sort in numeric order (\fBobjectsize\fR, \fBauthordate\fR, \fBcommitterdate\fR, \fBcreatordate\fR, \fBtaggerdate\fR)\&. All other fields are used to sort in their byte\-value order\&.
413 There is also an option to sort by versions, this can be done by using the fieldname \fBversion:refname\fR or its alias \fBv:refname\fR\&.
415 In any case, a field name that refers to a field inapplicable to the object referred by the ref does not cause an error\&. It returns an empty string instead\&.
417 As a special case for the date\-type fields, you may specify a format for the date by adding \fB:\fR followed by date format name (see the values the \fB\-\-date\fR option to \fBgit-rev-list\fR(1) takes)\&.
419 Some atoms like %(align) and %(if) always require a matching %(end)\&. We call them "opening atoms" and sometimes denote them as %($open)\&.
421 When a scripting language specific quoting is in effect, everything between a top\-level opening atom and its matching %(end) is evaluated according to the semantics of the opening atom and only its result from the top\-level is quoted\&.
424 An example directly producing formatted text\&. Show the most recent 3 tagged commits:
432 git for\-each\-ref \-\-count=3 \-\-sort=\*(Aq\-*authordate\*(Aq \e
433 \-\-format=\*(AqFrom: %(*authorname) %(*authoremail)
439 \*(Aq \*(Aqrefs/tags\*(Aq
446 A simple example showing the use of shell eval on the output, demonstrating the use of \-\-shell\&. List the prefixes of all heads:
454 git for\-each\-ref \-\-shell \-\-format="ref=%(refname)" refs/heads | \e
466 A bit more elaborate report on tags, demonstrating that the format may be an entire script:
489 # could be a lightweight tag
491 kind="Lightweight tag"
499 echo "$kind $T points at a $t object $o"
500 if test "z$t" = zcommit
502 echo "The commit was authored by $n $e
507 Its message reads as:
509 echo "$b" | sed \-e "s/^/ /"
514 eval=`git for\-each\-ref \-\-shell \-\-format="$fmt" \e
515 \-\-sort=\*(Aq*objecttype\*(Aq \e
516 \-\-sort=\-taggerdate \e
525 An example to show the usage of %(if)\&...%(then)\&...%(else)\&...%(end)\&. This prefixes the current branch with a star\&.
531 git for\-each\-ref \-\-format="%(if)%(HEAD)%(then)* %(else) %(end)%(refname:short)" refs/heads/
538 An example to show the usage of %(if)\&...%(then)\&...%(end)\&. This prints the authorname, if present\&.
544 git for\-each\-ref \-\-format="%(refname)%(if)%(authorname)%(then) Authored by: %(authorname)%(end)"
552 Note that the sizes of objects on disk are reported accurately, but care should be taken in drawing conclusions about which refs or objects are responsible for disk usage\&. The size of a packed non\-delta object may be much larger than the size of objects which delta against it, but the choice of which object is the base and which is the delta is arbitrary and is subject to change during a repack\&.
554 Note also that multiple copies of an object may be present in the object database; in this case, it is undefined which copy\(cqs size or delta base will be reported\&.
557 When combining multiple \fB\-\-contains\fR and \fB\-\-no\-contains\fR filters, only references that contain at least one of the \fB\-\-contains\fR commits and contain none of the \fB\-\-no\-contains\fR commits are shown\&.
559 When combining multiple \fB\-\-merged\fR and \fB\-\-no\-merged\fR filters, only references that are reachable from at least one of the \fB\-\-merged\fR commits and from none of the \fB\-\-no\-merged\fR commits are shown\&.
562 \fBgit-show-ref\fR(1)
565 Part of the \fBgit\fR(1) suite