1GIT-FOR-EACH-REF(1)               Git Manual               GIT-FOR-EACH-REF(1)
2
3
4

NAME

6       git-for-each-ref - Output information on each ref
7

SYNOPSIS

9           git-for-each-ref [--count=<count>]*
10                              [--shell|--perl|--python|--tcl]
11                              [--sort=<key>]* [--format=<format>] [<pattern>]
12

DESCRIPTION

14       Iterate over all refs that match <pattern> and show them according to
15       the given <format>, after sorting them according to the given set of
16       <key>. If <max> is given, stop after showing that many refs. The
17       interpolated values in <format> can optionally be quoted as string
18       literals in the specified host language allowing their direct
19       evaluation in that language.
20

OPTIONS

22       <count>
23           By default the command shows all refs that match <pattern>. This
24           option makes it stop after showing that many refs.
25
26       <key>
27           A field name to sort on. Prefix - to sort in descending order of
28           the value. When unspecified, refname is used. More than one sort
29           keys can be given.
30
31       <format>
32           A string that interpolates %(fieldname) from the object pointed at
33           by a ref being shown. If fieldname is prefixed with an asterisk (*)
34           and the ref points at a tag object, the value for the field in the
35           object tag refers is used. When unspecified, defaults to
36           %(objectname) SPC %(objecttype) TAB %(refname). It also
37           interpolates %% to %, and %xx where xx are hex digits interpolates
38           to character with hex code xx; for example %00 interpolates to \0
39           (NUL), %09 to \t (TAB) and %0a to \n (LF).
40
41       <pattern>
42           If given, the name of the ref is matched against this using
43           fnmatch(3). Refs that do not match the pattern are not shown.
44
45       --shell, --perl, --python, --tcl
46           If given, strings that substitute %(fieldname) placeholders are
47           quoted as string literals suitable for the specified host language.
48           This is meant to produce a scriptlet that can directly be `eval`ed.
49

FIELD NAMES

51       Various values from structured fields in referenced objects can be used
52       to interpolate into the resulting output, or as sort keys.
53
54       For all objects, the following names can be used:
55
56       refname
57           The name of the ref (the part after $GIT_DIR/).
58
59       objecttype
60           The type of the object (blob, tree, commit, tag).
61
62       objectsize
63           The size of the object (the same as git-cat-file -s reports).
64
65       objectname
66           The object name (aka SHA-1).
67       In addition to the above, for commit and tag objects, the header field
68       names (tree, parent, object, type, and tag) can be used to specify the
69       value in the header field.
70
71       Fields that have name-email-date tuple as its value (author, committer,
72       and tagger) can be suffixed with name, email, and date to extract the
73       named component.
74
75       The first line of the message in a commit and tag object is subject,
76       the remaining lines are body. The whole message is contents.
77
78       For sorting purposes, fields with numeric values sort in numeric order
79       (objectsize, authordate, committerdate, taggerdate). All other fields
80       are used to sort in their byte-value order.
81
82       In any case, a field name that refers to a field inapplicable to the
83       object referred by the ref does not cause an error. It returns an empty
84       string instead.
85

EXAMPLES

87       An example directly producing formatted text. Show the most recent 3
88       tagged commits::
89
90
91
92           #!/bin/sh
93
94           git-for-each-ref --count=3 --sort=´-*authordate´ \
95           --format=´From: %(*authorname) %(*authoremail)
96           Subject: %(*subject)
97           Date: %(*authordate)
98           Ref: %(*refname)
99
100           %(*body)
101           ´ ´refs/tags´
102
103       A simple example showing the use of shell eval on the output,
104       demonstrating the use of --shell. List the prefixes of all heads::
105
106
107
108           #!/bin/sh
109
110           git-for-each-ref --shell --format="ref=%(refname)" refs/heads | \
111           while read entry
112           do
113                   eval "$entry"
114                   echo `dirname $ref`
115           done
116
117       A bit more elaborate report on tags, demonstrating that the format may
118       be an entire script::
119
120
121
122           #!/bin/sh
123
124           fmt=´
125                   r=%(refname)
126                   t=%(*objecttype)
127                   T=${r#refs/tags/}
128
129                   o=%(*objectname)
130                   n=%(*authorname)
131                   e=%(*authoremail)
132                   s=%(*subject)
133                   d=%(*authordate)
134                   b=%(*body)
135
136                   kind=Tag
137                   if test "z$t" = z
138                   then
139                           # could be a lightweight tag
140                           t=%(objecttype)
141                           kind="Lightweight tag"
142                           o=%(objectname)
143                           n=%(authorname)
144                           e=%(authoremail)
145                           s=%(subject)
146                           d=%(authordate)
147                           b=%(body)
148                   fi
149                   echo "$kind $T points at a $t object $o"
150                   if test "z$t" = zcommit
151                   then
152                           echo "The commit was authored by $n $e
153           at $d, and titled
154
155               $s
156
157           Its message reads as:
158           "
159                           echo "$b" | sed -e "s/^/    /"
160                           echo
161                   fi
162           ´
163
164           eval=`git-for-each-ref --shell --format="$fmt" \
165                   --sort=´*objecttype´ \
166                   --sort=-taggerdate \
167                   refs/tags`
168           eval "$eval"
169
170
171
172
173Git 1.5.3.3                       10/09/2007               GIT-FOR-EACH-REF(1)
Impressum