blob: f57e69bc83e33e3de3d02e339fd71066b93e7d4d [file] [log] [blame]
Junio C Hamanoff4b4312006-10-25 22:55:311git-for-each-ref(1)
2===================
3
4NAME
5----
6git-for-each-ref - Output information on each ref
7
8SYNOPSIS
9--------
Junio C Hamanoa9b8d242007-05-19 04:51:5510[verse]
Junio C Hamanofce7c7e2008-07-02 03:06:3811'git for-each-ref' [--count=<count>] [--shell|--perl|--python|--tcl]
Junio C Hamanod2179ef2010-10-22 04:12:1712 [(--sort=<key>)...] [--format=<format>] [<pattern>...]
Junio C Hamano1eb56092015-10-05 20:39:5313 [--points-at <object>] [(--merged | --no-merged) [<object>]]
14 [--contains [<object>]]
Junio C Hamanoff4b4312006-10-25 22:55:3115
16DESCRIPTION
17-----------
18
19Iterate over all refs that match `<pattern>` and show them
20according to the given `<format>`, after sorting them according
Junio C Hamanoa2f46622008-09-03 05:20:3121to the given set of `<key>`. If `<count>` is given, stop after
Junio C Hamanof9771f62007-01-17 17:42:3022showing that many refs. The interpolated values in `<format>`
Junio C Hamanoff4b4312006-10-25 22:55:3123can optionally be quoted as string literals in the specified
24host language allowing their direct evaluation in that language.
25
26OPTIONS
27-------
28<count>::
29By default the command shows all refs that match
30`<pattern>`. This option makes it stop after showing
31that many refs.
32
33<key>::
34A field name to sort on. Prefix `-` to sort in
35descending order of the value. When unspecified,
Junio C Hamanof7c042d2008-06-06 22:50:5336`refname` is used. You may use the --sort=<key> option
37multiple times, in which case the last key becomes the primary
38key.
Junio C Hamanoff4b4312006-10-25 22:55:3139
40<format>::
41A string that interpolates `%(fieldname)` from the
42object pointed at by a ref being shown. If `fieldname`
43is prefixed with an asterisk (`*`) and the ref points
44at a tag object, the value for the field in the object
45tag refers is used. When unspecified, defaults to
Junio C Hamano4de43af2006-10-28 21:29:0146`%(objectname) SPC %(objecttype) TAB %(refname)`.
47It also interpolates `%%` to `%`, and `%xx` where `xx`
48are hex digits interpolates to character with hex code
49`xx`; for example `%00` interpolates to `\0` (NUL),
50`%09` to `\t` (TAB) and `%0a` to `\n` (LF).
Junio C Hamanoff4b4312006-10-25 22:55:3151
Junio C Hamano9e395072008-07-31 22:11:2152<pattern>...::
Junio C Hamanof7c042d2008-06-06 22:50:5353If one or more patterns are given, only refs are shown that
Junio C Hamanocb1c44f2008-08-06 06:19:3354match against at least one pattern, either using fnmatch(3) or
Junio C Hamanof7c042d2008-06-06 22:50:5355literally, in the latter case matching completely or from the
56beginning up to a slash.
Junio C Hamanoff4b4312006-10-25 22:55:3157
Junio C Hamanoeb415992008-06-08 22:49:4758--shell::
59--perl::
60--python::
61--tcl::
Junio C Hamanoff4b4312006-10-25 22:55:3162If given, strings that substitute `%(fieldname)`
63placeholders are quoted as string literals suitable for
64the specified host language. This is meant to produce
65a scriptlet that can directly be `eval`ed.
66
Junio C Hamano1eb56092015-10-05 20:39:5367--points-at <object>::
68Only list refs which points at the given object.
69
70--merged [<object>]::
71Only list refs whose tips are reachable from the
72specified commit (HEAD if not specified).
73
74--no-merged [<object>]::
75Only list refs whose tips are not reachable from the
76specified commit (HEAD if not specified).
77
78--contains [<object>]::
Junio C Hamano5996b672016-04-13 22:01:4179Only list refs which contain the specified commit (HEAD if not
Junio C Hamano1eb56092015-10-05 20:39:5380specified).
Junio C Hamanoff4b4312006-10-25 22:55:3181
82FIELD NAMES
83-----------
84
85Various values from structured fields in referenced objects can
86be used to interpolate into the resulting output, or as sort
87keys.
88
89For all objects, the following names can be used:
90
91refname::
Junio C Hamano42f855f2007-02-06 00:09:3892The name of the ref (the part after $GIT_DIR/).
Junio C Hamano5e4d8de2008-09-19 06:27:0293For a non-ambiguous short name of the ref append `:short`.
Junio C Hamano3bd66e92009-04-18 06:17:5694The option core.warnAmbiguousRefs is used to select the strict
Junio C Hamano19c20762016-02-01 23:38:0595abbreviation mode. If `strip=<N>` is appended, strips `<N>`
96slash-separated path components from the front of the refname
97(e.g., `%(refname:strip=2)` turns `refs/tags/foo` into `foo`.
98`<N>` must be a positive integer. If a displayed ref has fewer
99components than `<N>`, the command aborts with an error.
Junio C Hamanoff4b4312006-10-25 22:55:31100
101objecttype::
102The type of the object (`blob`, `tree`, `commit`, `tag`).
103
104objectsize::
Junio C Hamano1aa40d22010-01-21 17:46:43105The size of the object (the same as 'git cat-file -s' reports).
Junio C Hamanoff4b4312006-10-25 22:55:31106
107objectname::
108The object name (aka SHA-1).
Junio C Hamanoe97d5772010-05-19 08:13:58109For a non-ambiguous abbreviation of the object name append `:short`.
Junio C Hamanoff4b4312006-10-25 22:55:31110
Junio C Hamano98e32c32009-04-13 02:39:53111upstream::
112The name of a local ref which can be considered ``upstream''
113from the displayed ref. Respects `:short` in the same way as
Junio C Hamanof079f702013-12-06 23:43:18114`refname` above. Additionally respects `:track` to show
115"[ahead N, behind M]" and `:trackshort` to show the terse
116version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
117or "=" (in sync). Has no effect if the ref does not have
118tracking information associated with it.
119
Junio C Hamano975f4db2015-06-05 20:28:29120push::
121The name of a local ref which represents the `@{push}` location
122for the displayed ref. Respects `:short`, `:track`, and
123`:trackshort` options as `upstream` does. Produces an empty
124string if no `@{push}` ref is configured.
125
Junio C Hamanof079f702013-12-06 23:43:18126HEAD::
127'*' if HEAD matches current ref (the checked out branch), ' '
128otherwise.
129
130color::
131Change output color. Followed by `:<colorname>`, where names
132are described in `color.branch.*`.
Junio C Hamano98e32c32009-04-13 02:39:53133
Junio C Hamano1eb56092015-10-05 20:39:53134align::
135Left-, middle-, or right-align the content between
Junio C Hamano76df4f72016-02-26 22:13:10136%(align:...) and %(end). The "align:" is followed by
137`width=<width>` and `position=<position>` in any order
138separated by a comma, where the `<position>` is either left,
139right or middle, default being left and `<width>` is the total
140length of the content with alignment. For brevity, the
141"width=" and/or "position=" prefixes may be omitted, and bare
142<width> and <position> used instead. For instance,
143`%(align:<width>,<position>)`. If the contents length is more
144than the width then no alignment is performed. If used with
Junio C Hamano92d80372016-07-13 22:00:05145`--quote` everything in between %(align:...) and %(end) is
Junio C Hamano76df4f72016-02-26 22:13:10146quoted, but if nested then only the topmost level performs
147quoting.
Junio C Hamano1eb56092015-10-05 20:39:53148
Junio C Hamanoff4b4312006-10-25 22:55:31149In addition to the above, for commit and tag objects, the header
150field names (`tree`, `parent`, `object`, `type`, and `tag`) can
151be used to specify the value in the header field.
152
Junio C Hamano4e6ba272016-01-20 23:23:19153For commit and tag objects, the special `creatordate` and `creator`
154fields will correspond to the appropriate date or name-email-date tuple
155from the `committer` or `tagger` fields depending on the object type.
156These are intended for working on a mix of annotated and lightweight tags.
157
Junio C Hamanoff4b4312006-10-25 22:55:31158Fields that have name-email-date tuple as its value (`author`,
159`committer`, and `tagger`) can be suffixed with `name`, `email`,
160and `date` to extract the named component.
161
Junio C Hamano8fb66e52011-10-05 20:59:51162The complete message in a commit and tag object is `contents`.
Junio C Hamano281fd392012-09-17 23:57:41163Its first line is `contents:subject`, where subject is the concatenation
164of all lines of the commit message up to the first blank line. The next
165line is 'contents:body', where body is all of the lines after the first
Junio C Hamano1eb56092015-10-05 20:39:53166blank line. The optional GPG signature is `contents:signature`. The
167first `N` lines of the message is obtained using `contents:lines=N`.
Junio C Hamanoff4b4312006-10-25 22:55:31168
Junio C Hamano4e6ba272016-01-20 23:23:19169For sorting purposes, fields with numeric values sort in numeric order
170(`objectsize`, `authordate`, `committerdate`, `creatordate`, `taggerdate`).
Junio C Hamanoff4b4312006-10-25 22:55:31171All other fields are used to sort in their byte-value order.
172
Junio C Hamano1eb56092015-10-05 20:39:53173There is also an option to sort by versions, this can be done by using
174the fieldname `version:refname` or its alias `v:refname`.
175
Junio C Hamanoff4b4312006-10-25 22:55:31176In any case, a field name that refers to a field inapplicable to
177the object referred by the ref does not cause an error. It
178returns an empty string instead.
179
Junio C Hamano1b50ce92007-10-03 12:05:53180As a special case for the date-type fields, you may specify a format for
Junio C Hamano1eb56092015-10-05 20:39:53181the date by adding `:` followed by date format name (see the
Junio C Hamano198b1f12016-05-17 22:27:24182values the `--date` option to linkgit:git-rev-list[1] takes).
Junio C Hamano1b50ce92007-10-03 12:05:53183
Junio C Hamanoff4b4312006-10-25 22:55:31184
185EXAMPLES
186--------
187
188An example directly producing formatted text. Show the most recent
Junio C Hamanoa8cc1d82011-03-10 01:18:121893 tagged commits:
Junio C Hamanoff4b4312006-10-25 22:55:31190
191------------
192#!/bin/sh
193
Junio C Hamanofce7c7e2008-07-02 03:06:38194git for-each-ref --count=3 --sort='-*authordate' \
Junio C Hamanoff4b4312006-10-25 22:55:31195--format='From: %(*authorname) %(*authoremail)
196Subject: %(*subject)
197Date: %(*authordate)
198Ref: %(*refname)
199
200%(*body)
201' 'refs/tags'
202------------
203
204
205A simple example showing the use of shell eval on the output,
Junio C Hamanoa8cc1d82011-03-10 01:18:12206demonstrating the use of --shell. List the prefixes of all heads:
Junio C Hamanoff4b4312006-10-25 22:55:31207------------
208#!/bin/sh
209
Junio C Hamanofce7c7e2008-07-02 03:06:38210git for-each-ref --shell --format="ref=%(refname)" refs/heads | \
Junio C Hamanoff4b4312006-10-25 22:55:31211while read entry
212do
213eval "$entry"
214echo `dirname $ref`
215done
216------------
217
218
219A bit more elaborate report on tags, demonstrating that the format
Junio C Hamanoa8cc1d82011-03-10 01:18:12220may be an entire script:
Junio C Hamanoff4b4312006-10-25 22:55:31221------------
222#!/bin/sh
223
224fmt='
225r=%(refname)
226t=%(*objecttype)
227T=${r#refs/tags/}
228
229o=%(*objectname)
230n=%(*authorname)
231e=%(*authoremail)
232s=%(*subject)
233d=%(*authordate)
234b=%(*body)
235
236kind=Tag
237if test "z$t" = z
238then
239# could be a lightweight tag
240t=%(objecttype)
241kind="Lightweight tag"
242o=%(objectname)
243n=%(authorname)
244e=%(authoremail)
245s=%(subject)
246d=%(authordate)
247b=%(body)
248fi
249echo "$kind $T points at a $t object $o"
250if test "z$t" = zcommit
251then
252echo "The commit was authored by $n $e
253at $d, and titled
254
255 $s
256
257Its message reads as:
258"
259echo "$b" | sed -e "s/^/ /"
260echo
261fi
262'
263
Junio C Hamanofce7c7e2008-07-02 03:06:38264eval=`git for-each-ref --shell --format="$fmt" \
Junio C Hamanoff4b4312006-10-25 22:55:31265--sort='*objecttype' \
266--sort=-taggerdate \
267refs/tags`
268eval "$eval"
269------------
Junio C Hamanoa8cc1d82011-03-10 01:18:12270
Junio C Hamanofd98be82014-01-22 22:45:38271SEE ALSO
272--------
273linkgit:git-show-ref[1]
274
Junio C Hamanoa8cc1d82011-03-10 01:18:12275GIT
276---
277Part of the linkgit:git[1] suite