updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-for-each-ref.xml
blob4989add298979e82ff9515b59db893d0725ed09e
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
3 \r
4 <article lang="en" id="git-for-each-ref(1)">\r
5 <articleinfo>\r
6     <title>git-for-each-ref(1)</title>\r
7 <indexterm>\r
8 <primary>git-for-each-ref(1)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-for-each-ref - Output information on each ref</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git for-each-ref</emphasis> [--count=&lt;count&gt;] [--shell|--perl|--python|--tcl]\r
19                    [(--sort=&lt;key&gt;)&#8230;] [--format=&lt;format&gt;] [&lt;pattern&gt;&#8230;]</literallayout>\r
20 </blockquote>\r
21 </simplesect>\r
22 <simplesect id="_description">\r
23 <title>DESCRIPTION</title>\r
24 <simpara>Iterate over all refs that match <emphasis>&lt;pattern&gt;</emphasis> and show them\r
25 according to the given <emphasis>&lt;format&gt;</emphasis>, after sorting them according\r
26 to the given set of <emphasis>&lt;key&gt;</emphasis>.  If <emphasis>&lt;count&gt;</emphasis> is given, stop after\r
27 showing that many refs.  The interpolated values in <emphasis>&lt;format&gt;</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
30 </simplesect>\r
31 <simplesect id="_options">\r
32 <title>OPTIONS</title>\r
33 <variablelist>\r
34 <varlistentry>\r
35 <term>\r
36 &lt;count&gt;\r
37 </term>\r
38 <listitem>\r
39 <simpara>\r
40         By default the command shows all refs that match\r
41         <emphasis>&lt;pattern&gt;</emphasis>.  This option makes it stop after showing\r
42         that many refs.\r
43 </simpara>\r
44 </listitem>\r
45 </varlistentry>\r
46 <varlistentry>\r
47 <term>\r
48 &lt;key&gt;\r
49 </term>\r
50 <listitem>\r
51 <simpara>\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=&lt;key&gt; option\r
55         multiple times, in which case the last key becomes the primary\r
56         key.\r
57 </simpara>\r
58 </listitem>\r
59 </varlistentry>\r
60 <varlistentry>\r
61 <term>\r
62 &lt;format&gt;\r
63 </term>\r
64 <listitem>\r
65 <simpara>\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
76 </simpara>\r
77 </listitem>\r
78 </varlistentry>\r
79 <varlistentry>\r
80 <term>\r
81 &lt;pattern&gt;&#8230;\r
82 </term>\r
83 <listitem>\r
84 <simpara>\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
89 </simpara>\r
90 </listitem>\r
91 </varlistentry>\r
92 <varlistentry>\r
93 <term>\r
94 --shell\r
95 </term>\r
96 <term>\r
97 --perl\r
98 </term>\r
99 <term>\r
100 --python\r
101 </term>\r
102 <term>\r
103 --tcl\r
104 </term>\r
105 <listitem>\r
106 <simpara>\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
111 </simpara>\r
112 </listitem>\r
113 </varlistentry>\r
114 </variablelist>\r
115 </simplesect>\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
120 keys.</simpara>\r
121 <simpara>For all objects, the following names can be used:</simpara>\r
122 <variablelist>\r
123 <varlistentry>\r
124 <term>\r
125 refname\r
126 </term>\r
127 <listitem>\r
128 <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
132         abbreviation mode.\r
133 </simpara>\r
134 </listitem>\r
135 </varlistentry>\r
136 <varlistentry>\r
137 <term>\r
138 objecttype\r
139 </term>\r
140 <listitem>\r
141 <simpara>\r
142         The type of the object (<emphasis>blob</emphasis>, <emphasis>tree</emphasis>, <emphasis>commit</emphasis>, <emphasis>tag</emphasis>).\r
143 </simpara>\r
144 </listitem>\r
145 </varlistentry>\r
146 <varlistentry>\r
147 <term>\r
148 objectsize\r
149 </term>\r
150 <listitem>\r
151 <simpara>\r
152         The size of the object (the same as <emphasis>git cat-file -s</emphasis> reports).\r
153 </simpara>\r
154 </listitem>\r
155 </varlistentry>\r
156 <varlistentry>\r
157 <term>\r
158 objectname\r
159 </term>\r
160 <listitem>\r
161 <simpara>\r
162         The object name (aka SHA-1).\r
163         For a non-ambiguous abbreviation of the object name append <emphasis>:short</emphasis>.\r
164 </simpara>\r
165 </listitem>\r
166 </varlistentry>\r
167 <varlistentry>\r
168 <term>\r
169 upstream\r
170 </term>\r
171 <listitem>\r
172 <simpara>\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
176 </simpara>\r
177 </listitem>\r
178 </varlistentry>\r
179 </variablelist>\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
200 </simplesect>\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
205 <screen>#!/bin/sh\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
211 Ref: %(*refname)\r
213 %(*body)\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
217 <screen>#!/bin/sh\r
219 git for-each-ref --shell --format="ref=%(refname)" refs/heads | \\r
220 while read entry\r
221 do\r
222         eval "$entry"\r
223         echo `dirname $ref`\r
224 done</screen>\r
225 <simpara>A bit more elaborate report on tags, demonstrating that the format\r
226 may be an entire script:</simpara>\r
227 <screen>#!/bin/sh\r
229 fmt='\r
230         r=%(refname)\r
231         t=%(*objecttype)\r
232         T=${r#refs/tags/}\r
234         o=%(*objectname)\r
235         n=%(*authorname)\r
236         e=%(*authoremail)\r
237         s=%(*subject)\r
238         d=%(*authordate)\r
239         b=%(*body)\r
241         kind=Tag\r
242         if test "z$t" = z\r
243         then\r
244                 # could be a lightweight tag\r
245                 t=%(objecttype)\r
246                 kind="Lightweight tag"\r
247                 o=%(objectname)\r
248                 n=%(authorname)\r
249                 e=%(authoremail)\r
250                 s=%(subject)\r
251                 d=%(authordate)\r
252                 b=%(body)\r
253         fi\r
254         echo "$kind $T points at a $t object $o"\r
255         if test "z$t" = zcommit\r
256         then\r
257                 echo "The commit was authored by $n $e\r
258 at $d, and titled\r
260     $s\r
262 Its message reads as:\r
264                 echo "$b" | sed -e "s/^/    /"\r
265                 echo\r
266         fi\r
269 eval=`git for-each-ref --shell --format="$fmt" \\r
270         --sort='*objecttype' \\r
271         --sort=-taggerdate \\r
272         refs/tags`\r
273 eval "$eval"</screen>\r
274 </simplesect>\r
275 <simplesect id="_author">\r
276 <title>Author</title>\r
277 <simpara>Written by Junio C Hamano &lt;<ulink url="mailto:gitster@pobox.com">gitster@pobox.com</ulink>&gt;.</simpara>\r
278 </simplesect>\r
279 <simplesect id="_documentation">\r
280 <title>Documentation</title>\r
281 <simpara>Documentation by Junio C Hamano and the git-list &lt;<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>&gt;.</simpara>\r
282 </simplesect>\r
283 <simplesect id="_git">\r
284 <title>GIT</title>\r
285 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
286 </simplesect>\r
287 </article>\r