blob: 06208c49901c6c7e73aa6b6d593e533f7cf57dc5 [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>]::
79Only list tags which contain the specified commit (HEAD if not
80specified).
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
95abbreviation mode.
Junio C Hamanoff4b4312006-10-25 22:55:3196
97objecttype::
98The type of the object (`blob`, `tree`, `commit`, `tag`).
99
100objectsize::
Junio C Hamano1aa40d22010-01-21 17:46:43101The size of the object (the same as 'git cat-file -s' reports).
Junio C Hamanoff4b4312006-10-25 22:55:31102
103objectname::
104The object name (aka SHA-1).
Junio C Hamanoe97d5772010-05-19 08:13:58105For a non-ambiguous abbreviation of the object name append `:short`.
Junio C Hamanoff4b4312006-10-25 22:55:31106
Junio C Hamano98e32c32009-04-13 02:39:53107upstream::
108The name of a local ref which can be considered ``upstream''
109from the displayed ref. Respects `:short` in the same way as
Junio C Hamanof079f702013-12-06 23:43:18110`refname` above. Additionally respects `:track` to show
111"[ahead N, behind M]" and `:trackshort` to show the terse
112version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
113or "=" (in sync). Has no effect if the ref does not have
114tracking information associated with it.
115
Junio C Hamano975f4db2015-06-05 20:28:29116push::
117The name of a local ref which represents the `@{push}` location
118for the displayed ref. Respects `:short`, `:track`, and
119`:trackshort` options as `upstream` does. Produces an empty
120string if no `@{push}` ref is configured.
121
Junio C Hamanof079f702013-12-06 23:43:18122HEAD::
123'*' if HEAD matches current ref (the checked out branch), ' '
124otherwise.
125
126color::
127Change output color. Followed by `:<colorname>`, where names
128are described in `color.branch.*`.
Junio C Hamano98e32c32009-04-13 02:39:53129
Junio C Hamano1eb56092015-10-05 20:39:53130align::
131Left-, middle-, or right-align the content between
132%(align:...) and %(end). The "align:" is followed by `<width>`
133and `<position>` in any order separated by a comma, where the
134`<position>` is either left, right or middle, default being
135left and `<width>` is the total length of the content with
136alignment. If the contents length is more than the width then
137no alignment is performed. If used with '--quote' everything
138in between %(align:...) and %(end) is quoted, but if nested
139then only the topmost level performs quoting.
140
Junio C Hamanoff4b4312006-10-25 22:55:31141In addition to the above, for commit and tag objects, the header
142field names (`tree`, `parent`, `object`, `type`, and `tag`) can
143be used to specify the value in the header field.
144
Junio C Hamano4e6ba272016-01-20 23:23:19145For commit and tag objects, the special `creatordate` and `creator`
146fields will correspond to the appropriate date or name-email-date tuple
147from the `committer` or `tagger` fields depending on the object type.
148These are intended for working on a mix of annotated and lightweight tags.
149
Junio C Hamanoff4b4312006-10-25 22:55:31150Fields that have name-email-date tuple as its value (`author`,
151`committer`, and `tagger`) can be suffixed with `name`, `email`,
152and `date` to extract the named component.
153
Junio C Hamano8fb66e52011-10-05 20:59:51154The complete message in a commit and tag object is `contents`.
Junio C Hamano281fd392012-09-17 23:57:41155Its first line is `contents:subject`, where subject is the concatenation
156of all lines of the commit message up to the first blank line. The next
157line is 'contents:body', where body is all of the lines after the first
Junio C Hamano1eb56092015-10-05 20:39:53158blank line. The optional GPG signature is `contents:signature`. The
159first `N` lines of the message is obtained using `contents:lines=N`.
Junio C Hamanoff4b4312006-10-25 22:55:31160
Junio C Hamano4e6ba272016-01-20 23:23:19161For sorting purposes, fields with numeric values sort in numeric order
162(`objectsize`, `authordate`, `committerdate`, `creatordate`, `taggerdate`).
Junio C Hamanoff4b4312006-10-25 22:55:31163All other fields are used to sort in their byte-value order.
164
Junio C Hamano1eb56092015-10-05 20:39:53165There is also an option to sort by versions, this can be done by using
166the fieldname `version:refname` or its alias `v:refname`.
167
Junio C Hamanoff4b4312006-10-25 22:55:31168In any case, a field name that refers to a field inapplicable to
169the object referred by the ref does not cause an error. It
170returns an empty string instead.
171
Junio C Hamano1b50ce92007-10-03 12:05:53172As a special case for the date-type fields, you may specify a format for
Junio C Hamano1eb56092015-10-05 20:39:53173the date by adding `:` followed by date format name (see the
174values the `--date` option to linkgit::git-rev-list[1] takes).
Junio C Hamano1b50ce92007-10-03 12:05:53175
Junio C Hamanoff4b4312006-10-25 22:55:31176
177EXAMPLES
178--------
179
180An example directly producing formatted text. Show the most recent
Junio C Hamanoa8cc1d82011-03-10 01:18:121813 tagged commits:
Junio C Hamanoff4b4312006-10-25 22:55:31182
183------------
184#!/bin/sh
185
Junio C Hamanofce7c7e2008-07-02 03:06:38186git for-each-ref --count=3 --sort='-*authordate' \
Junio C Hamanoff4b4312006-10-25 22:55:31187--format='From: %(*authorname) %(*authoremail)
188Subject: %(*subject)
189Date: %(*authordate)
190Ref: %(*refname)
191
192%(*body)
193' 'refs/tags'
194------------
195
196
197A simple example showing the use of shell eval on the output,
Junio C Hamanoa8cc1d82011-03-10 01:18:12198demonstrating the use of --shell. List the prefixes of all heads:
Junio C Hamanoff4b4312006-10-25 22:55:31199------------
200#!/bin/sh
201
Junio C Hamanofce7c7e2008-07-02 03:06:38202git for-each-ref --shell --format="ref=%(refname)" refs/heads | \
Junio C Hamanoff4b4312006-10-25 22:55:31203while read entry
204do
205eval "$entry"
206echo `dirname $ref`
207done
208------------
209
210
211A bit more elaborate report on tags, demonstrating that the format
Junio C Hamanoa8cc1d82011-03-10 01:18:12212may be an entire script:
Junio C Hamanoff4b4312006-10-25 22:55:31213------------
214#!/bin/sh
215
216fmt='
217r=%(refname)
218t=%(*objecttype)
219T=${r#refs/tags/}
220
221o=%(*objectname)
222n=%(*authorname)
223e=%(*authoremail)
224s=%(*subject)
225d=%(*authordate)
226b=%(*body)
227
228kind=Tag
229if test "z$t" = z
230then
231# could be a lightweight tag
232t=%(objecttype)
233kind="Lightweight tag"
234o=%(objectname)
235n=%(authorname)
236e=%(authoremail)
237s=%(subject)
238d=%(authordate)
239b=%(body)
240fi
241echo "$kind $T points at a $t object $o"
242if test "z$t" = zcommit
243then
244echo "The commit was authored by $n $e
245at $d, and titled
246
247 $s
248
249Its message reads as:
250"
251echo "$b" | sed -e "s/^/ /"
252echo
253fi
254'
255
Junio C Hamanofce7c7e2008-07-02 03:06:38256eval=`git for-each-ref --shell --format="$fmt" \
Junio C Hamanoff4b4312006-10-25 22:55:31257--sort='*objecttype' \
258--sort=-taggerdate \
259refs/tags`
260eval "$eval"
261------------
Junio C Hamanoa8cc1d82011-03-10 01:18:12262
Junio C Hamanofd98be82014-01-22 22:45:38263SEE ALSO
264--------
265linkgit:git-show-ref[1]
266
Junio C Hamanoa8cc1d82011-03-10 01:18:12267GIT
268---
269Part of the linkgit:git[1] suite