Skip to main content

Searching for a Git commit by name with grep

Posted in Development and Git

Sometimes I need to find a commit. It’s easy if the commit I’m looking for was very recent – a quick git log will do the job.

If the commit I’m after was a few weeks ago, it’s likely that I’m going to have some scrolling to do. git log is quite noisy, so I might add --oneline to keep it easy to scan.

But what if the commit I’m after was last year? I’m going to have to do a lot of scrolling! That’s where --grep comes in.

I wanted to reference some work I did on the <address> element in an article I wrote earlier this week, so I filtered my git log like this:

git log --grep="address" --oneline

This gave me a dozen or so results. Much easier to find what I was after!

Once I had the commit, I copied the commit hash and took a closer look with git show d773c20, and this was what the commit looked like:

commit d773c20fd45d993d96abe7f42e0336b8f3ff8e35
Author: Martin Underhill <martin@tempertemper.net>
Date: Thu Jun 27 21:13:26 2019 +0100

Adds role of group to address to stop duplicate contentinfo

diff --git a/src/site/_includes/footer.html b/src/site/_includes/footer.html
index b7a1e44..247838b 100644
--- a/src/site/_includes/footer.html
+++ b/src/site/_includes/footer.html
@@ -12,7 +12,7 @@
</nav>
<div class="copyright">
<p>&copy;&nbsp;copyright 2009&nbsp;to&nbsp;2024</p>
- <address class="adr">
+ <address class="adr" role="group">
<span class="org">tempertemper Web Design Ltd</span>,
<span class="extended-address">Clavering House</span>,
<span class="street-address">Clavering Place</span>,
(END)

Exactly what I was after! I then used the date to find the PR that the commit was part of and, in turn, the link to the commit on GitHub.

This exercise was also a good reminder to keep commits small and regular, and to name them descriptively!

Accessibility in your inbox

I send an accessibility-centric newsletter on the last day of every month, containing:

  • A roundup of the articles I’ve posted
  • A hot pick from my archives
  • Some interesting posts from around the web

I don’t collect any data on when, where or if people open the emails I send them. Your email will only be used to send you newsletters and will never be passed on. You can unsubscribe at any time.

More posts

Here are a couple more posts for you to enjoy. If that’s not enough, have a look at the full list.

  1. Alt text for CSS generated content

    There’s an interesting feature in Safari 17.4 that allows content added with CSS to have ‘alt’ text. I’m not sure how I feel about this.

  2. The accessibility conversations you want to be having

    In most companies, accessibility conversations centre around WCAG compliance, but that’s just the start. Thinking beyond that is where you want to be!