RSSAmplifier

Hearthside by Caleb Hearth · Apr 17, 2025

Tally All Git Trailers in a Repository

0
Sign in to vote or save

Hearthside

I’ve been using a lot of Git Trailers in my commit messages recently and as my thinking on which trailer keys to use has evolved, it’s been useful to look back at which ones have been used before.

git log’s --format flag can provide all sorts of useful information, including trailers. Let’s take a look:

❯ git log --format="%(trailers:keyonly)" |
  grep '\w\+' |
  grep -v https |
  sort |
  uniq -c |
  sort

We start by asking Git to give us the full log with the format of only the trailer keys. That gets passed to a (naïve, but good enough) grep '\w\+ to remove empty lines, then again through grep -v https to remove lines with “trailers” which are just links1. Finally we tally up the results with sort | uniq -c | sort which is one of my toolbox commands to get tallies of distinct lines sorted by count ascending (so that the most common trailers are nearest the prompt).

That’s helped me remember that Issue is the key I like for linking to the related issue tracker, and not Fixes or Closes which will close related issues in GitHub or Gitlab when they’re merged in (not always what I want).

Some other favorites are:

  • Co-authored-by for pairs, Reviewed-by (occasionally) for reviewers
  • Documented-at, Documented-by, or Reference for linking to library or product docs
  • Related-Issue for linking to issues that this commit doesn’t directly address
  • Follow-up for linking to an issue that I’m splitting off from this body of work
  • Feature, Fix, and Change for end-user-facing changelog entries, which I’ll script something up for to add to tags and release notes.
  • I’m experimenting with Conventional and Breaking-Change for Conventional Commits information.2

While Git trailers haven’t been widely adopted, there are a few others shouting into the void as it were about how they could be useful:

I’d love to hear what trailers you’re using, and why! And I feel like it may be time to revisit my commit messages article with a more experienced eye. Would that be interesting to you?

  1. In a previous post, I encouraged “including a link to the issue/story/card in the commit message”. I still believe that a full URL pointing to the issue is useful, but now that I know about Git trailers I think it should be one of them instead of “naked” in the commit message. 

  2. I refuse to use those in the subject because of the 50 character limit on subject lines, but throwing it into a trailer and relying on tools to expose it seems like a good alternative. 

Read the original on calebhearth.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.