| GIT-FORMAT-REV(1) | Git Manual | GIT-FORMAT-REV(1) |
NAME
git-format-rev - EXPERIMENTAL: Pretty format revisions on demand
SYNOPSIS
(EXPERIMENTAL!) git format-rev --stdin-mode=<mode> --format=<pretty> [--[no-]notes=<ref>] [-z] [--[no-]null-output] [--[no-]null-input]
DESCRIPTION
Pretty format revisions from standard input.
THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
OPTIONS
--stdin-mode=<mode>
revs
The argument rev is also accepted.
text
Anything that is parsed as an object name but that is not found to be a commit object name is left alone (echoed).
--format=<pretty>
--notes=<ref>, --no-notes
-z, --null
This is useful if both the input and output could contain newlines or if the input to this command also uses NUL character termination; see the INPUT AND OUTPUT FORMATS section below.
The mode --stdin-mode=text can have use for this option when it needs to process input like for example git last-modified -z; see the EXAMPLES section below.
--null-output, --no-null-output
This is useful if the output could contain newlines, for example if the %n (newline) atom is used.
--null-input, --no-null-input
This is useful if the input revision expressions could contain newlines.
INPUT AND OUTPUT FORMAT
The command uses newlines for both input and output termination by default. See the -z, --null-output, and --null-input options for using NUL character as the terminator.
The mode --stdin-mode=revs outputs one formatted commit followed by the terminator. This could either be called a line or a record in case "line" is too suggestive of newline termination.
Note that this means that the terminator character (newline or NUL) acts as a terminator, not a separator. In other words, the final line or record is also terminated by the terminator character.
The mode --stdin-mode=text replaces each object name with the formatted commit, i.e. the format %s would transform some commit object name to <subject> without any termination. Like this:
Did we not fix this in "<subject>"?
It is safe to interactively read and write from this command since each record is immediately flushed.
EXAMPLES
The command git-last-modified(1) shows the commit that each file was last modified in.
$ git last-modified -- README.md Makefile 7798034171030be0909c56377a4e0e10e6d2df93 Makefile c50fbb2dd225e7e82abba4380423ae105089f4d7 README.md
We can pipe the result to this command in order to replace the object name with the commit author.
$ git last-modified -- README.md Makefile |
git format-rev --stdin-mode=text --format=%an
Junio C Hamano Makefile
Todd Zullinger README.md
Another example is formatting commits in commit messages. Given this commit message:
Fix off-by-one error Fix off-by-one error introduced in e83c5163316f89bfbde7d9ab23ca2e25604af290. We thought we fixed this in 5569bf9bbedd63a00780fc5c110e0cfab3aa97b9 but that only covered 1/3 of the faulty cases.
We can format the commits and use par(1) to reflow the text, say in a commit-msg hook:
$ git config set hook.reference-commits.event commit-msg
$ git config set hook.reference-commits.command reference-commits
$ cat $(which reference-commits)
#/bin/sh
msg="$1"
rewritten=$(mktemp)
git format-rev --stdin-mode=text --format=reference <"$msg" |
par >"$rewritten"
mv "$rewritten" "$msg"
Which will produce something like this:
Fix off-by-one error Fix off-by-one error introduced in e83c5163316 (Implement better memory allocator, 2005-04-07). We thought we fixed this in 5569bf9bbed (Fix memory allocator, 2005-06-22) but that only covered 1/3 of the faulty cases.
DISCUSSION
This command lets you format any number of revisions in any order through one command invocation. Consider the git-last-modified(1) case from the EXAMPLES section above:
Two widely-used commands which pretty formats commits are git-log(1) and git-show(1). It turns out that they are not a good fit for the above use case.
In short, it is straightforward to use these two commands if you use one process per line. It is much more work if you just want to use one process, but still doable. In contrast, this problem is solved with just another shell pipeline with this command.
SEE ALSO
GIT
Part of the git(1) suite
| 2026-06-29 | Git 2.55.0 |