@@ -96,7 +96,9 @@ refname::
96
96
slash-separated path components from the front of the refname
97
97
(e.g., `%(refname:strip=2)` turns `refs/tags/foo` into `foo`.
98
98
`<N>` must be a positive integer. If a displayed ref has fewer
99
- components than `<N>`, the command aborts with an error.
99
+ components than `<N>`, the command aborts with an error. For the base
100
+ directory of the ref (i.e. foo in refs/foo/bar/boz) append
101
+ `:base`. For the entire directory path append `:dir`.
100
102
101
103
objecttype::
102
104
The type of the object (`blob`, `tree`, `commit`, `tag`).
@@ -107,21 +109,30 @@ objectsize::
107
109
objectname::
108
110
The object name (aka SHA-1).
109
111
For a non-ambiguous abbreviation of the object name append `:short`.
112
+ For an abbreviation of the object name with desired length append
113
+ `:short=<length>`, where the minimum length is MINIMUM_ABBREV. The
114
+ length may be exceeded to ensure unique object names.
115
+
110
116
111
117
upstream::
112
118
The name of a local ref which can be considered ``upstream''
113
- from the displayed ref. Respects `:short` in the same way as
114
- `refname` above. Additionally respects `:track` to show
115
- "[ahead N, behind M]" and `:trackshort` to show the terse
116
- version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
117
- or "=" (in sync). Has no effect if the ref does not have
118
- tracking information associated with it.
119
+ from the displayed ref. Respects `:short`, `:strip`, `:base`
120
+ and `:dir` in the same way as `refname` above. Additionally
121
+ respects `:track` to show "[ahead N, behind M]" and
122
+ `:trackshort` to show the terse version: ">" (ahead), "<"
123
+ (behind), "<>" (ahead and behind), or "=" (in sync). `:track`
124
+ also prints "[gone]" whenever unknown upstream ref is
125
+ encountered. Append `:track,nobracket` to show tracking
126
+ information without brackets (i.e "ahead N, behind M"). Has
127
+ no effect if the ref does not have tracking information
128
+ associated with it.
119
129
120
130
push::
121
- The name of a local ref which represents the `@{push}` location
122
- for the displayed ref. Respects `:short`, `:track`, and
123
- `:trackshort` options as `upstream` does. Produces an empty
124
- string if no `@{push}` ref is configured.
131
+ The name of a local ref which represents the `@{push}`
132
+ location for the displayed ref. Respects `:short`, `:strip`,
133
+ `:track`, `:trackshort`, `:base` and `:dir` options as
134
+ `upstream` does. Produces an empty string if no `@{push}` ref
135
+ is configured.
125
136
126
137
HEAD::
127
138
'*' if HEAD matches current ref (the checked out branch), ' '
@@ -141,10 +152,26 @@ align::
141
152
"width=" and/or "position=" prefixes may be omitted, and bare
142
153
<width> and <position> used instead. For instance,
143
154
`%(align:<width>,<position>)`. If the contents length is more
144
- than the width then no alignment is performed. If used with
145
- `--quote` everything in between %(align:...) and %(end) is
146
- quoted, but if nested then only the topmost level performs
147
- quoting.
155
+ than the width then no alignment is performed.
156
+
157
+ if::
158
+ Used as %(if)...%(then)...(%end) or
159
+ %(if)...%(then)...%(else)...%(end). If there is an atom with
160
+ value or string literal after the %(if) then everything after
161
+ the %(then) is printed, else if the %(else) atom is used, then
162
+ everything after %(else) is printed. We ignore space when
163
+ evaluating the string before %(then), this is useful when we
164
+ use the %(HEAD) atom which prints either "*" or " " and we
165
+ want to apply the 'if' condition only on the 'HEAD' ref.
166
+ Append ":equals=<string>" or ":notequals=<string>" to compare
167
+ the value between the %(if:...) and %(then) atoms with the
168
+ given string.
169
+
170
+ symref::
171
+ The ref which the given symbolic ref refers to. If not a
172
+ symbolic ref, nothing is printed. Respects the `:short`,
173
+ `:strip`, `:base` and `:dir` options in the same way as
174
+ `refname` above.
148
175
149
176
In addition to the above, for commit and tag objects, the header
150
177
field names (`tree`, `parent`, `object`, `type`, and `tag`) can
@@ -181,6 +208,20 @@ As a special case for the date-type fields, you may specify a format for
181
208
the date by adding `:` followed by date format name (see the
182
209
values the `--date` option to linkgit:git-rev-list[1] takes).
183
210
211
+ Some atoms like %(align) and %(if) always require a matching %(end).
212
+ We call them "opening atoms" and sometimes denote them as %($open).
213
+
214
+ When a scripting language specific quoting is in effect (i.e. one of
215
+ `--shell`, `--perl`, `--python`, `--tcl` is used), except for opening
216
+ atoms, replacement from every %(atom) is quoted when and only when it
217
+ appears at the top-level (that is, when it appears outside
218
+ %($open)...%(end)).
219
+
220
+ When a scripting language specific quoting is in effect, everything
221
+ between a top-level opening atom and its matching %(end) is evaluated
222
+ according to the semantics of the opening atom and its result is
223
+ quoted.
224
+
184
225
185
226
EXAMPLES
186
227
--------
@@ -268,6 +309,22 @@ eval=`git for-each-ref --shell --format="$fmt" \
268
309
eval "$eval"
269
310
------------
270
311
312
+
313
+ An example to show the usage of %(if)...%(then)...%(else)...%(end).
314
+ This prefixes the current branch with a star.
315
+
316
+ ------------
317
+ git for-each-ref --format="%(if)%(HEAD)%(then)* %(else) %(end)%(refname:short)" refs/heads/
318
+ ------------
319
+
320
+
321
+ An example to show the usage of %(if)...%(then)...%(end).
322
+ This prints the authorname, if present.
323
+
324
+ ------------
325
+ git for-each-ref --format="%(refname)%(if)%(authorname)%(then) %(color:red)Authored by: %(authorname)%(end)"
326
+ ------------
327
+
271
328
SEE ALSO
272
329
--------
273
330
linkgit:git-show-ref[1]
0 commit comments