1

In reading about git log, I have discovered it is possible to choose from an array of built-in formats (e.g. --pretty=reference) or create your own. Custom "PRETTY FORMATS" are quite capable, with many placeholders to choose from and the option to add colors too.

However, I have no need to create a format from scratch. I would rather tweak the presets that ship with git. Are the format strings for these presets available so I can pass them to

git log --pretty=format:<format-string>

and change them as desired?

1
  • Some of the "magic" (built in) formats can be reconstructed from directives, but some cannot. See VonC's answer. I think at some point the formatting language should be beefed-up and all formats should be converted to their directive equivalents, but I have no idea when or if this will ever actually happen. (It's not very high on my priority list... 😀 what's there works, and this would be a lot of work to implement, for no immediate gain.)
    – torek
    Commented Jun 25, 2022 at 11:39

2 Answers 2

2

You can see some of the preset format-string used by Git in builtin/shortlog.c#shortlog_add_commit(), for instance.

Example:

if (log->groups & SHORTLOG_GROUP_AUTHOR) {
        strbuf_reset(&ident);
        format_commit_message(commit,
                      log->email ? "%aN <%aE>" : "%aN",
                      &ident, &ctx);
        if (!HAS_MULTI_BITS(log->groups) ||
            strset_add(&dups, ident.buf))
            insert_one_record(log, ident.buf, oneline_str);
    }
    if (log->groups & SHORTLOG_GROUP_COMMITTER) {
        strbuf_reset(&ident);
        format_commit_message(commit,
                      log->email ? "%cN <%cE>" : "%cN",
                      &ident, &ctx);

But that illustrates that those preset are not available in a neat list somewhere, rather used directly in the Git source code.

1

You can consult all available preset options at https://git-scm.com/docs/pretty-formats

Note that you can build your own using format:<format-string>, all available options for the format string being also described in the man page above.

1
  • Those are the presets and custom formatting I refer to in my question. What I am asking is whether the format strings for those presets are available. I will edit my question to clarify that.
    – Shadorian
    Commented Jun 25, 2022 at 7:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.