1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/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 <literal><pattern></literal> and show them
\r
25 according to the given <literal><format></literal>, after sorting them according
\r
26 to the given set of <literal><key></literal>. If <literal><count></literal> is given, stop after
\r
27 showing that many refs. The interpolated values in <literal><format></literal>
\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 <literal><pattern></literal>. This option makes it stop after showing
\r
52 A field name to sort on. Prefix <literal>-</literal> to sort in
\r
53 descending order of the value. When unspecified,
\r
54 <literal>refname</literal> 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 <literal>%(fieldname)</literal> from the
\r
67 object pointed at by a ref being shown. If <literal>fieldname</literal>
\r
68 is prefixed with an asterisk (<literal>*</literal>) 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 <literal>%(objectname) SPC %(objecttype) TAB %(refname)</literal>.
\r
72 It also interpolates <literal>%%</literal> to <literal>%</literal>, and <literal>%xx</literal> where <literal>xx</literal>
\r
73 are hex digits interpolates to character with hex code
\r
74 <literal>xx</literal>; for example <literal>%00</literal> interpolates to <literal>\0</literal> (NUL),
\r
75 <literal>%09</literal> to <literal>\t</literal> (TAB) and <literal>%0a</literal> to <literal>\n</literal> (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 <literal>%(fieldname)</literal>
\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 <literal>:short</literal>.
\r
140 The type of the object (<literal>blob</literal>, <literal>tree</literal>, <literal>commit</literal>, <literal>tag</literal>).
\r
150 The size of the object (the same as <emphasis>git-cat-file -s</emphasis> reports).
\r
160 The object name (aka SHA-1).
\r
165 <simpara>In addition to the above, for commit and tag objects, the header
\r
166 field names (<literal>tree</literal>, <literal>parent</literal>, <literal>object</literal>, <literal>type</literal>, and <literal>tag</literal>) can
\r
167 be used to specify the value in the header field.</simpara>
\r
168 <simpara>Fields that have name-email-date tuple as its value (<literal>author</literal>,
\r
169 <literal>committer</literal>, and <literal>tagger</literal>) can be suffixed with <literal>name</literal>, <literal>email</literal>,
\r
170 and <literal>date</literal> to extract the named component.</simpara>
\r
171 <simpara>The first line of the message in a commit and tag object is
\r
172 <literal>subject</literal>, the remaining lines are <literal>body</literal>. The whole message
\r
173 is <literal>contents</literal>.</simpara>
\r
174 <simpara>For sorting purposes, fields with numeric values sort in numeric
\r
175 order (<literal>objectsize</literal>, <literal>authordate</literal>, <literal>committerdate</literal>, <literal>taggerdate</literal>).
\r
176 All other fields are used to sort in their byte-value order.</simpara>
\r
177 <simpara>In any case, a field name that refers to a field inapplicable to
\r
178 the object referred by the ref does not cause an error. It
\r
179 returns an empty string instead.</simpara>
\r
180 <simpara>As a special case for the date-type fields, you may specify a format for
\r
181 the date by adding one of <literal>:default</literal>, <literal>:relative</literal>, <literal>:short</literal>, <literal>:local</literal>,
\r
182 <literal>:iso8601</literal> or <literal>:rfc2822</literal> to the end of the fieldname; e.g.
\r
183 <literal>%(taggerdate:relative)</literal>.</simpara>
\r
185 <simplesect id="_examples">
\r
186 <title>EXAMPLES</title>
\r
187 <simpara>An example directly producing formatted text. Show the most recent
\r
188 3 tagged commits::</simpara>
\r
189 <literallayout>#!/bin/sh
\r
191 git for-each-ref --count=3 --sort='-*authordate' \
\r
192 --format='From: %(*authorname) %(*authoremail)
\r
193 Subject: %(*subject)
\r
194 Date: %(*authordate)
\r
198 ' 'refs/tags'</literallayout>
\r
199 <simpara>A simple example showing the use of shell eval on the output,
\r
200 demonstrating the use of --shell. List the prefixes of all heads::</simpara>
\r
201 <literallayout>#!/bin/sh
\r
203 git for-each-ref --shell --format="ref=%(refname)" refs/heads | \
\r
207 echo `dirname $ref`
\r
208 done</literallayout>
\r
209 <simpara>A bit more elaborate report on tags, demonstrating that the format
\r
210 may be an entire script::</simpara>
\r
211 <literallayout>#!/bin/sh
\r
228 # could be a lightweight tag
\r
230 kind="Lightweight tag"
\r
238 echo "$kind $T points at a $t object $o"
\r
239 if test "z$t" = zcommit
\r
241 echo "The commit was authored by $n $e
\r
246 Its message reads as:
\r
248 echo "$b" | sed -e "s/^/ /"
\r
253 eval=`git for-each-ref --shell --format="$fmt" \
\r
254 --sort='*objecttype' \
\r
255 --sort=-taggerdate \
\r
257 eval "$eval"</literallayout>
\r