1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
\r
4 <article lang="en" id="git-for-each-ref(1)">
\r
6 <title>git-for-each-ref(1)</title>
\r
8 <primary>git-for-each-ref(1)</primary>
\r
11 <simplesect id="_name">
\r
13 <simpara>git-for-each-ref - Output information on each ref</simpara>
\r
15 <simplesect id="_synopsis">
\r
16 <title>SYNOPSIS</title>
\r
18 <literallayout><emphasis>git for-each-ref</emphasis> [--count=<count>] [--shell|--perl|--python|--tcl]
\r
19 [(--sort=<key>)…] [--format=<format>] [<pattern>…]</literallayout>
\r
22 <simplesect id="_description">
\r
23 <title>DESCRIPTION</title>
\r
24 <simpara>Iterate over all refs that match <emphasis><pattern></emphasis> and show them
\r
25 according to the given <emphasis><format></emphasis>, after sorting them according
\r
26 to the given set of <emphasis><key></emphasis>. If <emphasis><count></emphasis> is given, stop after
\r
27 showing that many refs. The interpolated values in <emphasis><format></emphasis>
\r
28 can optionally be quoted as string literals in the specified
\r
29 host language allowing their direct evaluation in that language.</simpara>
\r
31 <simplesect id="_options">
\r
32 <title>OPTIONS</title>
\r
40 By default the command shows all refs that match
\r
41 <emphasis><pattern></emphasis>. This option makes it stop after showing
\r
52 A field name to sort on. Prefix <emphasis>-</emphasis> to sort in
\r
53 descending order of the value. When unspecified,
\r
54 <emphasis>refname</emphasis> is used. You may use the --sort=<key> option
\r
55 multiple times, in which case the last key becomes the primary
\r
66 A string that interpolates <emphasis>%(fieldname)</emphasis> from the
\r
67 object pointed at by a ref being shown. If <emphasis>fieldname</emphasis>
\r
68 is prefixed with an asterisk (<emphasis>*</emphasis>) and the ref points
\r
69 at a tag object, the value for the field in the object
\r
70 tag refers is used. When unspecified, defaults to
\r
71 <emphasis>%(objectname) SPC %(objecttype) TAB %(refname)</emphasis>.
\r
72 It also interpolates <emphasis>%%</emphasis> to <emphasis>%</emphasis>, and <emphasis>%xx</emphasis> where <emphasis>xx</emphasis>
\r
73 are hex digits interpolates to character with hex code
\r
74 <emphasis>xx</emphasis>; for example <emphasis>%00</emphasis> interpolates to <emphasis>\0</emphasis> (NUL),
\r
75 <emphasis>%09</emphasis> to <emphasis>\t</emphasis> (TAB) and <emphasis>%0a</emphasis> to <emphasis>\n</emphasis> (LF).
\r
81 <pattern>…
\r
85 If one or more patterns are given, only refs are shown that
\r
86 match against at least one pattern, either using fnmatch(3) or
\r
87 literally, in the latter case matching completely or from the
\r
88 beginning up to a slash.
\r
107 If given, strings that substitute <emphasis>%(fieldname)</emphasis>
\r
108 placeholders are quoted as string literals suitable for
\r
109 the specified host language. This is meant to produce
\r
110 a scriptlet that can directly be `eval`ed.
\r
116 <simplesect id="_field_names">
\r
117 <title>FIELD NAMES</title>
\r
118 <simpara>Various values from structured fields in referenced objects can
\r
119 be used to interpolate into the resulting output, or as sort
\r
121 <simpara>For all objects, the following names can be used:</simpara>
\r
129 The name of the ref (the part after $GIT_DIR/).
\r
130 For a non-ambiguous short name of the ref append <emphasis>:short</emphasis>.
\r
131 The option core.warnAmbiguousRefs is used to select the strict
\r
142 The type of the object (<emphasis>blob</emphasis>, <emphasis>tree</emphasis>, <emphasis>commit</emphasis>, <emphasis>tag</emphasis>).
\r
152 The size of the object (the same as <emphasis>git cat-file -s</emphasis> reports).
\r
162 The object name (aka SHA-1).
\r
163 For a non-ambiguous abbreviation of the object name append <emphasis>:short</emphasis>.
\r
173 The name of a local ref which can be considered upstream
\r
174 from the displayed ref. Respects <emphasis>:short</emphasis> in the same way as
\r
175 <emphasis>refname</emphasis> above.
\r
180 <simpara>In addition to the above, for commit and tag objects, the header
\r
181 field names (<emphasis>tree</emphasis>, <emphasis>parent</emphasis>, <emphasis>object</emphasis>, <emphasis>type</emphasis>, and <emphasis>tag</emphasis>) can
\r
182 be used to specify the value in the header field.</simpara>
\r
183 <simpara>Fields that have name-email-date tuple as its value (<emphasis>author</emphasis>,
\r
184 <emphasis>committer</emphasis>, and <emphasis>tagger</emphasis>) can be suffixed with <emphasis>name</emphasis>, <emphasis>email</emphasis>,
\r
185 and <emphasis>date</emphasis> to extract the named component.</simpara>
\r
186 <simpara>The complete message in a commit and tag object is <emphasis>contents</emphasis>.
\r
187 Its first line is <emphasis>contents:subject</emphasis>, the remaining lines
\r
188 are <emphasis>contents:body</emphasis> and the optional GPG signature
\r
189 is <emphasis>contents:signature</emphasis>.</simpara>
\r
190 <simpara>For sorting purposes, fields with numeric values sort in numeric
\r
191 order (<emphasis>objectsize</emphasis>, <emphasis>authordate</emphasis>, <emphasis>committerdate</emphasis>, <emphasis>taggerdate</emphasis>).
\r
192 All other fields are used to sort in their byte-value order.</simpara>
\r
193 <simpara>In any case, a field name that refers to a field inapplicable to
\r
194 the object referred by the ref does not cause an error. It
\r
195 returns an empty string instead.</simpara>
\r
196 <simpara>As a special case for the date-type fields, you may specify a format for
\r
197 the date by adding one of <emphasis>:default</emphasis>, <emphasis>:relative</emphasis>, <emphasis>:short</emphasis>, <emphasis>:local</emphasis>,
\r
198 <emphasis>:iso8601</emphasis> or <emphasis>:rfc2822</emphasis> to the end of the fieldname; e.g.
\r
199 <emphasis>%(taggerdate:relative)</emphasis>.</simpara>
\r
201 <simplesect id="_examples">
\r
202 <title>EXAMPLES</title>
\r
203 <simpara>An example directly producing formatted text. Show the most recent
\r
204 3 tagged commits:</simpara>
\r
207 git for-each-ref --count=3 --sort='-*authordate' \
\r
208 --format='From: %(*authorname) %(*authoremail)
\r
209 Subject: %(*subject)
\r
210 Date: %(*authordate)
\r
214 ' 'refs/tags'</screen>
\r
215 <simpara>A simple example showing the use of shell eval on the output,
\r
216 demonstrating the use of --shell. List the prefixes of all heads:</simpara>
\r
219 git for-each-ref --shell --format="ref=%(refname)" refs/heads | \
\r
223 echo `dirname $ref`
\r
225 <simpara>A bit more elaborate report on tags, demonstrating that the format
\r
226 may be an entire script:</simpara>
\r
244 # could be a lightweight tag
\r
246 kind="Lightweight tag"
\r
254 echo "$kind $T points at a $t object $o"
\r
255 if test "z$t" = zcommit
\r
257 echo "The commit was authored by $n $e
\r
262 Its message reads as:
\r
264 echo "$b" | sed -e "s/^/ /"
\r
269 eval=`git for-each-ref --shell --format="$fmt" \
\r
270 --sort='*objecttype' \
\r
271 --sort=-taggerdate \
\r
273 eval "$eval"</screen>
\r
275 <simplesect id="_author">
\r
276 <title>Author</title>
\r
277 <simpara>Written by Junio C Hamano <<ulink url="mailto:gitster@pobox.com">gitster@pobox.com</ulink>>.</simpara>
\r
279 <simplesect id="_documentation">
\r
280 <title>Documentation</title>
\r
281 <simpara>Documentation by Junio C Hamano and the git-list <<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>>.</simpara>
\r
283 <simplesect id="_git">
\r
285 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r