OSDN Git Service

merge original branch.
[tortoisegit/TortoiseGitJp.git] / doc / source / en / TortoiseGit / git_doc / git-for-each-ref.html.xml
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
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;]\* [--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 <literal>&lt;pattern&gt;</literal> and show them\r
25 according to the given <literal>&lt;format&gt;</literal>, after sorting them according\r
26 to the given set of <literal>&lt;key&gt;</literal>.  If <literal>&lt;count&gt;</literal> is given, stop after\r
27 showing that many refs.  The interpolated values in <literal>&lt;format&gt;</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
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         <literal>&lt;pattern&gt;</literal>.  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 <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=&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 <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
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 <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
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 <literal>:short</literal>.\r
131 </simpara>\r
132 </listitem>\r
133 </varlistentry>\r
134 <varlistentry>\r
135 <term>\r
136 objecttype\r
137 </term>\r
138 <listitem>\r
139 <simpara>\r
140         The type of the object (<literal>blob</literal>, <literal>tree</literal>, <literal>commit</literal>, <literal>tag</literal>).\r
141 </simpara>\r
142 </listitem>\r
143 </varlistentry>\r
144 <varlistentry>\r
145 <term>\r
146 objectsize\r
147 </term>\r
148 <listitem>\r
149 <simpara>\r
150         The size of the object (the same as <emphasis>git-cat-file -s</emphasis> reports).\r
151 </simpara>\r
152 </listitem>\r
153 </varlistentry>\r
154 <varlistentry>\r
155 <term>\r
156 objectname\r
157 </term>\r
158 <listitem>\r
159 <simpara>\r
160         The object name (aka SHA-1).\r
161 </simpara>\r
162 </listitem>\r
163 </varlistentry>\r
164 </variablelist>\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
184 </simplesect>\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
190 \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
195 Ref: %(*refname)\r
196 \r
197 %(*body)\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
202 \r
203 git for-each-ref --shell --format="ref=%(refname)" refs/heads | \\r
204 while read entry\r
205 do\r
206         eval "$entry"\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
212 \r
213 fmt='\r
214         r=%(refname)\r
215         t=%(*objecttype)\r
216         T=${r#refs/tags/}\r
217 \r
218         o=%(*objectname)\r
219         n=%(*authorname)\r
220         e=%(*authoremail)\r
221         s=%(*subject)\r
222         d=%(*authordate)\r
223         b=%(*body)\r
224 \r
225         kind=Tag\r
226         if test "z$t" = z\r
227         then\r
228                 # could be a lightweight tag\r
229                 t=%(objecttype)\r
230                 kind="Lightweight tag"\r
231                 o=%(objectname)\r
232                 n=%(authorname)\r
233                 e=%(authoremail)\r
234                 s=%(subject)\r
235                 d=%(authordate)\r
236                 b=%(body)\r
237         fi\r
238         echo "$kind $T points at a $t object $o"\r
239         if test "z$t" = zcommit\r
240         then\r
241                 echo "The commit was authored by $n $e\r
242 at $d, and titled\r
243 \r
244     $s\r
245 \r
246 Its message reads as:\r
247 "\r
248                 echo "$b" | sed -e "s/^/    /"\r
249                 echo\r
250         fi\r
251 '\r
252 \r
253 eval=`git for-each-ref --shell --format="$fmt" \\r
254         --sort='*objecttype' \\r
255         --sort=-taggerdate \\r
256         refs/tags`\r
257 eval "$eval"</literallayout>\r
258 </simplesect>\r
259 </article>\r