blob: abe13f3bedaf55dbefc03d26b934351107ff50af [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
Junio C Hamano52b1cfb2016-12-20 00:18:3682--ignore-case::
83Sorting and filtering refs are case insensitive.
84
Junio C Hamanoff4b4312006-10-25 22:55:3185FIELD NAMES
86-----------
87
88Various values from structured fields in referenced objects can
89be used to interpolate into the resulting output, or as sort
90keys.
91
92For all objects, the following names can be used:
93
94refname::
Junio C Hamano42f855f2007-02-06 00:09:3895The name of the ref (the part after $GIT_DIR/).
Junio C Hamano5e4d8de2008-09-19 06:27:0296For a non-ambiguous short name of the ref append `:short`.
Junio C Hamano3bd66e92009-04-18 06:17:5697The option core.warnAmbiguousRefs is used to select the strict
Junio C Hamano19c20762016-02-01 23:38:0598abbreviation mode. If `strip=<N>` is appended, strips `<N>`
99slash-separated path components from the front of the refname
100(e.g., `%(refname:strip=2)` turns `refs/tags/foo` into `foo`.
101`<N>` must be a positive integer. If a displayed ref has fewer
102components than `<N>`, the command aborts with an error.
Junio C Hamanoff4b4312006-10-25 22:55:31103
104objecttype::
105The type of the object (`blob`, `tree`, `commit`, `tag`).
106
107objectsize::
Junio C Hamano1aa40d22010-01-21 17:46:43108The size of the object (the same as 'git cat-file -s' reports).
Junio C Hamanoff4b4312006-10-25 22:55:31109
110objectname::
111The object name (aka SHA-1).
Junio C Hamanoe97d5772010-05-19 08:13:58112For a non-ambiguous abbreviation of the object name append `:short`.
Junio C Hamanoff4b4312006-10-25 22:55:31113
Junio C Hamano98e32c32009-04-13 02:39:53114upstream::
115The name of a local ref which can be considered ``upstream''
116from the displayed ref. Respects `:short` in the same way as
Junio C Hamanof079f702013-12-06 23:43:18117`refname` above. Additionally respects `:track` to show
118"[ahead N, behind M]" and `:trackshort` to show the terse
119version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
120or "=" (in sync). Has no effect if the ref does not have
121tracking information associated with it.
122
Junio C Hamano975f4db2015-06-05 20:28:29123push::
124The name of a local ref which represents the `@{push}` location
125for the displayed ref. Respects `:short`, `:track`, and
126`:trackshort` options as `upstream` does. Produces an empty
127string if no `@{push}` ref is configured.
128
Junio C Hamanof079f702013-12-06 23:43:18129HEAD::
130'*' if HEAD matches current ref (the checked out branch), ' '
131otherwise.
132
133color::
134Change output color. Followed by `:<colorname>`, where names
135are described in `color.branch.*`.
Junio C Hamano98e32c32009-04-13 02:39:53136
Junio C Hamano1eb56092015-10-05 20:39:53137align::
138Left-, middle-, or right-align the content between
Junio C Hamano76df4f72016-02-26 22:13:10139%(align:...) and %(end). The "align:" is followed by
140`width=<width>` and `position=<position>` in any order
141separated by a comma, where the `<position>` is either left,
142right or middle, default being left and `<width>` is the total
143length of the content with alignment. For brevity, the
144"width=" and/or "position=" prefixes may be omitted, and bare
145<width> and <position> used instead. For instance,
146`%(align:<width>,<position>)`. If the contents length is more
147than the width then no alignment is performed. If used with
Junio C Hamano92d80372016-07-13 22:00:05148`--quote` everything in between %(align:...) and %(end) is
Junio C Hamano76df4f72016-02-26 22:13:10149quoted, but if nested then only the topmost level performs
150quoting.
Junio C Hamano1eb56092015-10-05 20:39:53151
Junio C Hamanoff4b4312006-10-25 22:55:31152In addition to the above, for commit and tag objects, the header
153field names (`tree`, `parent`, `object`, `type`, and `tag`) can
154be used to specify the value in the header field.
155
Junio C Hamano4e6ba272016-01-20 23:23:19156For commit and tag objects, the special `creatordate` and `creator`
157fields will correspond to the appropriate date or name-email-date tuple
158from the `committer` or `tagger` fields depending on the object type.
159These are intended for working on a mix of annotated and lightweight tags.
160
Junio C Hamanoff4b4312006-10-25 22:55:31161Fields that have name-email-date tuple as its value (`author`,
162`committer`, and `tagger`) can be suffixed with `name`, `email`,
163and `date` to extract the named component.
164
Junio C Hamano8fb66e52011-10-05 20:59:51165The complete message in a commit and tag object is `contents`.
Junio C Hamano281fd392012-09-17 23:57:41166Its first line is `contents:subject`, where subject is the concatenation
167of all lines of the commit message up to the first blank line. The next
168line is 'contents:body', where body is all of the lines after the first
Junio C Hamano1eb56092015-10-05 20:39:53169blank line. The optional GPG signature is `contents:signature`. The
170first `N` lines of the message is obtained using `contents:lines=N`.
Junio C Hamano52b1cfb2016-12-20 00:18:36171Additionally, the trailers as interpreted by linkgit:git-interpret-trailers[1]
172are obtained as 'contents:trailers'.
Junio C Hamanoff4b4312006-10-25 22:55:31173
Junio C Hamano4e6ba272016-01-20 23:23:19174For sorting purposes, fields with numeric values sort in numeric order
175(`objectsize`, `authordate`, `committerdate`, `creatordate`, `taggerdate`).
Junio C Hamanoff4b4312006-10-25 22:55:31176All other fields are used to sort in their byte-value order.
177
Junio C Hamano1eb56092015-10-05 20:39:53178There is also an option to sort by versions, this can be done by using
179the fieldname `version:refname` or its alias `v:refname`.
180
Junio C Hamanoff4b4312006-10-25 22:55:31181In any case, a field name that refers to a field inapplicable to
182the object referred by the ref does not cause an error. It
183returns an empty string instead.
184
Junio C Hamano1b50ce92007-10-03 12:05:53185As a special case for the date-type fields, you may specify a format for
Junio C Hamano1eb56092015-10-05 20:39:53186the date by adding `:` followed by date format name (see the
Junio C Hamano198b1f12016-05-17 22:27:24187values the `--date` option to linkgit:git-rev-list[1] takes).
Junio C Hamano1b50ce92007-10-03 12:05:53188
Junio C Hamanoff4b4312006-10-25 22:55:31189
190EXAMPLES
191--------
192
193An example directly producing formatted text. Show the most recent
Junio C Hamanoa8cc1d82011-03-10 01:18:121943 tagged commits:
Junio C Hamanoff4b4312006-10-25 22:55:31195
196------------
197#!/bin/sh
198
Junio C Hamanofce7c7e2008-07-02 03:06:38199git for-each-ref --count=3 --sort='-*authordate' \
Junio C Hamanoff4b4312006-10-25 22:55:31200--format='From: %(*authorname) %(*authoremail)
201Subject: %(*subject)
202Date: %(*authordate)
203Ref: %(*refname)
204
205%(*body)
206' 'refs/tags'
207------------
208
209
210A simple example showing the use of shell eval on the output,
Junio C Hamanoa8cc1d82011-03-10 01:18:12211demonstrating the use of --shell. List the prefixes of all heads:
Junio C Hamanoff4b4312006-10-25 22:55:31212------------
213#!/bin/sh
214
Junio C Hamanofce7c7e2008-07-02 03:06:38215git for-each-ref --shell --format="ref=%(refname)" refs/heads | \
Junio C Hamanoff4b4312006-10-25 22:55:31216while read entry
217do
218eval "$entry"
219echo `dirname $ref`
220done
221------------
222
223
224A bit more elaborate report on tags, demonstrating that the format
Junio C Hamanoa8cc1d82011-03-10 01:18:12225may be an entire script:
Junio C Hamanoff4b4312006-10-25 22:55:31226------------
227#!/bin/sh
228
229fmt='
230r=%(refname)
231t=%(*objecttype)
232T=${r#refs/tags/}
233
234o=%(*objectname)
235n=%(*authorname)
236e=%(*authoremail)
237s=%(*subject)
238d=%(*authordate)
239b=%(*body)
240
241kind=Tag
242if test "z$t" = z
243then
244# could be a lightweight tag
245t=%(objecttype)
246kind="Lightweight tag"
247o=%(objectname)
248n=%(authorname)
249e=%(authoremail)
250s=%(subject)
251d=%(authordate)
252b=%(body)
253fi
254echo "$kind $T points at a $t object $o"
255if test "z$t" = zcommit
256then
257echo "The commit was authored by $n $e
258at $d, and titled
259
260 $s
261
262Its message reads as:
263"
264echo "$b" | sed -e "s/^/ /"
265echo
266fi
267'
268
Junio C Hamanofce7c7e2008-07-02 03:06:38269eval=`git for-each-ref --shell --format="$fmt" \
Junio C Hamanoff4b4312006-10-25 22:55:31270--sort='*objecttype' \
271--sort=-taggerdate \
272refs/tags`
273eval "$eval"
274------------
Junio C Hamanoa8cc1d82011-03-10 01:18:12275
Junio C Hamanofd98be82014-01-22 22:45:38276SEE ALSO
277--------
278linkgit:git-show-ref[1]
279
Junio C Hamanoa8cc1d82011-03-10 01:18:12280GIT
281---
282Part of the linkgit:git[1] suite