]> git.ipfire.org Git - thirdparty/git.git/blob - Documentation/git-for-each-ref.txt
for-each-ref: add '--merged' and '--no-merged' options
[thirdparty/git.git] / Documentation / git-for-each-ref.txt
1 git-for-each-ref(1)
2 ===================
3
4 NAME
5 ----
6 git-for-each-ref - Output information on each ref
7
8 SYNOPSIS
9 --------
10 [verse]
11 'git for-each-ref' [--count=<count>] [--shell|--perl|--python|--tcl]
12 [(--sort=<key>)...] [--format=<format>] [<pattern>...]
13 [--points-at <object>] [(--merged | --no-merged) [<object>]]
14
15 DESCRIPTION
16 -----------
17
18 Iterate over all refs that match `<pattern>` and show them
19 according to the given `<format>`, after sorting them according
20 to the given set of `<key>`. If `<count>` is given, stop after
21 showing that many refs. The interpolated values in `<format>`
22 can optionally be quoted as string literals in the specified
23 host language allowing their direct evaluation in that language.
24
25 OPTIONS
26 -------
27 <count>::
28 By default the command shows all refs that match
29 `<pattern>`. This option makes it stop after showing
30 that many refs.
31
32 <key>::
33 A field name to sort on. Prefix `-` to sort in
34 descending order of the value. When unspecified,
35 `refname` is used. You may use the --sort=<key> option
36 multiple times, in which case the last key becomes the primary
37 key.
38
39 <format>::
40 A string that interpolates `%(fieldname)` from the
41 object pointed at by a ref being shown. If `fieldname`
42 is prefixed with an asterisk (`*`) and the ref points
43 at a tag object, the value for the field in the object
44 tag refers is used. When unspecified, defaults to
45 `%(objectname) SPC %(objecttype) TAB %(refname)`.
46 It also interpolates `%%` to `%`, and `%xx` where `xx`
47 are hex digits interpolates to character with hex code
48 `xx`; for example `%00` interpolates to `\0` (NUL),
49 `%09` to `\t` (TAB) and `%0a` to `\n` (LF).
50
51 <pattern>...::
52 If one or more patterns are given, only refs are shown that
53 match against at least one pattern, either using fnmatch(3) or
54 literally, in the latter case matching completely or from the
55 beginning up to a slash.
56
57 --shell::
58 --perl::
59 --python::
60 --tcl::
61 If given, strings that substitute `%(fieldname)`
62 placeholders are quoted as string literals suitable for
63 the specified host language. This is meant to produce
64 a scriptlet that can directly be `eval`ed.
65
66 --points-at <object>::
67 Only list refs which points at the given object.
68
69 --merged [<object>]::
70 Only list refs whose tips are reachable from the
71 specified commit (HEAD if not specified).
72
73 --no-merged [<object>]::
74 Only list refs whose tips are not reachable from the
75 specified commit (HEAD if not specified).
76
77 FIELD NAMES
78 -----------
79
80 Various values from structured fields in referenced objects can
81 be used to interpolate into the resulting output, or as sort
82 keys.
83
84 For all objects, the following names can be used:
85
86 refname::
87 The name of the ref (the part after $GIT_DIR/).
88 For a non-ambiguous short name of the ref append `:short`.
89 The option core.warnAmbiguousRefs is used to select the strict
90 abbreviation mode.
91
92 objecttype::
93 The type of the object (`blob`, `tree`, `commit`, `tag`).
94
95 objectsize::
96 The size of the object (the same as 'git cat-file -s' reports).
97
98 objectname::
99 The object name (aka SHA-1).
100 For a non-ambiguous abbreviation of the object name append `:short`.
101
102 upstream::
103 The name of a local ref which can be considered ``upstream''
104 from the displayed ref. Respects `:short` in the same way as
105 `refname` above. Additionally respects `:track` to show
106 "[ahead N, behind M]" and `:trackshort` to show the terse
107 version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
108 or "=" (in sync). Has no effect if the ref does not have
109 tracking information associated with it.
110
111 push::
112 The name of a local ref which represents the `@{push}` location
113 for the displayed ref. Respects `:short`, `:track`, and
114 `:trackshort` options as `upstream` does. Produces an empty
115 string if no `@{push}` ref is configured.
116
117 HEAD::
118 '*' if HEAD matches current ref (the checked out branch), ' '
119 otherwise.
120
121 color::
122 Change output color. Followed by `:<colorname>`, where names
123 are described in `color.branch.*`.
124
125 In addition to the above, for commit and tag objects, the header
126 field names (`tree`, `parent`, `object`, `type`, and `tag`) can
127 be used to specify the value in the header field.
128
129 Fields that have name-email-date tuple as its value (`author`,
130 `committer`, and `tagger`) can be suffixed with `name`, `email`,
131 and `date` to extract the named component.
132
133 The complete message in a commit and tag object is `contents`.
134 Its first line is `contents:subject`, where subject is the concatenation
135 of all lines of the commit message up to the first blank line. The next
136 line is 'contents:body', where body is all of the lines after the first
137 blank line. Finally, the optional GPG signature is `contents:signature`.
138
139 For sorting purposes, fields with numeric values sort in numeric
140 order (`objectsize`, `authordate`, `committerdate`, `taggerdate`).
141 All other fields are used to sort in their byte-value order.
142
143 In any case, a field name that refers to a field inapplicable to
144 the object referred by the ref does not cause an error. It
145 returns an empty string instead.
146
147 As a special case for the date-type fields, you may specify a format for
148 the date by adding one of `:default`, `:relative`, `:short`, `:local`,
149 `:iso8601`, `:rfc2822` or `:raw` to the end of the fieldname; e.g.
150 `%(taggerdate:relative)`.
151
152
153 EXAMPLES
154 --------
155
156 An example directly producing formatted text. Show the most recent
157 3 tagged commits:
158
159 ------------
160 #!/bin/sh
161
162 git for-each-ref --count=3 --sort='-*authordate' \
163 --format='From: %(*authorname) %(*authoremail)
164 Subject: %(*subject)
165 Date: %(*authordate)
166 Ref: %(*refname)
167
168 %(*body)
169 ' 'refs/tags'
170 ------------
171
172
173 A simple example showing the use of shell eval on the output,
174 demonstrating the use of --shell. List the prefixes of all heads:
175 ------------
176 #!/bin/sh
177
178 git for-each-ref --shell --format="ref=%(refname)" refs/heads | \
179 while read entry
180 do
181 eval "$entry"
182 echo `dirname $ref`
183 done
184 ------------
185
186
187 A bit more elaborate report on tags, demonstrating that the format
188 may be an entire script:
189 ------------
190 #!/bin/sh
191
192 fmt='
193 r=%(refname)
194 t=%(*objecttype)
195 T=${r#refs/tags/}
196
197 o=%(*objectname)
198 n=%(*authorname)
199 e=%(*authoremail)
200 s=%(*subject)
201 d=%(*authordate)
202 b=%(*body)
203
204 kind=Tag
205 if test "z$t" = z
206 then
207 # could be a lightweight tag
208 t=%(objecttype)
209 kind="Lightweight tag"
210 o=%(objectname)
211 n=%(authorname)
212 e=%(authoremail)
213 s=%(subject)
214 d=%(authordate)
215 b=%(body)
216 fi
217 echo "$kind $T points at a $t object $o"
218 if test "z$t" = zcommit
219 then
220 echo "The commit was authored by $n $e
221 at $d, and titled
222
223 $s
224
225 Its message reads as:
226 "
227 echo "$b" | sed -e "s/^/ /"
228 echo
229 fi
230 '
231
232 eval=`git for-each-ref --shell --format="$fmt" \
233 --sort='*objecttype' \
234 --sort=-taggerdate \
235 refs/tags`
236 eval "$eval"
237 ------------
238
239 SEE ALSO
240 --------
241 linkgit:git-show-ref[1]
242
243 GIT
244 ---
245 Part of the linkgit:git[1] suite