Home Explore Blog CI



git

6th chunk of `Documentation/git-for-each-ref.adoc`
4cd4f3598879a253242c82ec769913b3a381797471f84b38000000010000085d
 "subject".

contents:signature::
	The optional GPG signature of the tag.

contents:lines=N::
	The first `N` lines of the message.

Additionally, the trailers as interpreted by linkgit:git-interpret-trailers[1]
are obtained as `trailers[:options]` (or by using the historical alias
`contents:trailers[:options]`). For valid [:option] values see `trailers`
section of linkgit:git-log[1].

For sorting purposes, fields with numeric values sort in numeric order
(`objectsize`, `authordate`, `committerdate`, `creatordate`, `taggerdate`).
All other fields are used to sort in their byte-value order.

There is also an option to sort by versions, this can be done by using
the fieldname `version:refname` or its alias `v:refname`.

In any case, a field name that refers to a field inapplicable to
the object referred by the ref does not cause an error.  It
returns an empty string instead.

As a special case for the date-type fields, you may specify a format for the
date by adding `:` followed by date format name (see the values the `--date`
option to linkgit:git-rev-list[1] takes). If this formatting is provided in
a `--sort` key, references will be sorted according to the byte-value of the
formatted string rather than the numeric value of the underlying timestamp.

Some atoms like %(align) and %(if) always require a matching %(end).
We call them "opening atoms" and sometimes denote them as %($open).

When a scripting language specific quoting is in effect, everything
between a top-level opening atom and its matching %(end) is evaluated
according to the semantics of the opening atom and only its result
from the top-level is quoted.


EXAMPLES
--------

An example directly producing formatted text.  Show the most recent
3 tagged commits:

------------
#!/bin/sh

git for-each-ref --count=3 --sort='-*authordate' \
--format='From: %(*authorname) %(*authoremail)
Subject: %(*subject)
Date: %(*authordate)
Ref: %(*refname)

%(*body)
' 'refs/tags'
------------


A simple example showing the use of shell eval on the output,
demonstrating the use of --shell.  List the prefixes of all heads:

------------
#!/bin/sh

git for-each-ref

Title: Git Format Specifiers and Sorting Options
Summary
This section describes additional Git format specifiers for messages, including subject, signature, and trailers, as well as options for sorting by numeric values, versions, and custom date formats. It also covers error handling for inapplicable fields and provides examples of using these specifiers in scripts, including formatting text and evaluating output using shell eval.