1git-for-each-ref(1) 2=================== 3 4NAME 5---- 6git-for-each-ref - Output information on each ref 7 8SYNOPSIS 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 15DESCRIPTION 16----------- 17 18Iterate over all refs that match `<pattern>` and show them 19according to the given `<format>`, after sorting them according 20to the given set of `<key>`. If `<count>` is given, stop after 21showing that many refs. The interpolated values in `<format>` 22can optionally be quoted as string literals in the specified 23host language allowing their direct evaluation in that language. 24 25OPTIONS 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 77FIELD NAMES 78----------- 79 80Various values from structured fields in referenced objects can 81be used to interpolate into the resulting output, or as sort 82keys. 83 84For all objects, the following names can be used: 85 86refname:: 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 92objecttype:: 93 The type of the object (`blob`, `tree`, `commit`, `tag`). 94 95objectsize:: 96 The size of the object (the same as 'git cat-file -s' reports). 97 98objectname:: 99 The object name (aka SHA-1). 100 For a non-ambiguous abbreviation of the object name append `:short`. 101 102upstream:: 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 111push:: 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 117HEAD:: 118 '*' if HEAD matches current ref (the checked out branch), ' ' 119 otherwise. 120 121color:: 122 Change output color. Followed by `:<colorname>`, where names 123 are described in `color.branch.*`. 124 125In addition to the above, for commit and tag objects, the header 126field names (`tree`, `parent`, `object`, `type`, and `tag`) can 127be used to specify the value in the header field. 128 129Fields that have name-email-date tuple as its value (`author`, 130`committer`, and `tagger`) can be suffixed with `name`, `email`, 131and `date` to extract the named component. 132 133The complete message in a commit and tag object is `contents`. 134Its first line is `contents:subject`, where subject is the concatenation 135of all lines of the commit message up to the first blank line. The next 136line is 'contents:body', where body is all of the lines after the first 137blank line. Finally, the optional GPG signature is `contents:signature`. 138 139For sorting purposes, fields with numeric values sort in numeric 140order (`objectsize`, `authordate`, `committerdate`, `taggerdate`). 141All other fields are used to sort in their byte-value order. 142 143In any case, a field name that refers to a field inapplicable to 144the object referred by the ref does not cause an error. It 145returns an empty string instead. 146 147As a special case for the date-type fields, you may specify a format for 148the 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 153EXAMPLES 154-------- 155 156An example directly producing formatted text. Show the most recent 1573 tagged commits: 158 159------------ 160#!/bin/sh 161 162git for-each-ref --count=3 --sort='-*authordate' \ 163--format='From: %(*authorname) %(*authoremail) 164Subject: %(*subject) 165Date: %(*authordate) 166Ref: %(*refname) 167 168%(*body) 169' 'refs/tags' 170------------ 171 172 173A simple example showing the use of shell eval on the output, 174demonstrating the use of --shell. List the prefixes of all heads: 175------------ 176#!/bin/sh 177 178git for-each-ref --shell --format="ref=%(refname)" refs/heads | \ 179while read entry 180do 181 eval "$entry" 182 echo `dirname $ref` 183done 184------------ 185 186 187A bit more elaborate report on tags, demonstrating that the format 188may be an entire script: 189------------ 190#!/bin/sh 191 192fmt=' 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 221at $d, and titled 222 223 $s 224 225Its message reads as: 226" 227 echo "$b" | sed -e "s/^/ /" 228 echo 229 fi 230' 231 232eval=`git for-each-ref --shell --format="$fmt" \ 233 --sort='*objecttype' \ 234 --sort=-taggerdate \ 235 refs/tags` 236eval "$eval" 237------------ 238 239SEE ALSO 240-------- 241linkgit:git-show-ref[1] 242 243GIT 244--- 245Part of the linkgit:git[1] suite