Skip to content
Gun.io
git cowboy
April 21, 2025 · 2 min read

How to do a Git Log Search

TL;DR

git log --grep="<pattern>" searches commit messages.

git grep <pattern> $(git rev-list --all) searches the code itself.

Add filters (--author, --since, -- path/) or context flags (-p, -S, -G) to zero‑in fast.

Before we dive into terminal flags and one‑liners, here’s the situation in plain English:

Modern repositories often pack tens of thousands of commits. Manually scrolling or memorising hash IDs wastes time you could spend shipping code. What you really need is a small toolkit of repeatable search patterns that work the same way on every project. Whether it’s a fresh micro‑service, a sprawling monorepo, or a decade‑old SVN‑convert.

This guide distills those patterns into six bite‑size techniques, each paired with a real command you can copy‑paste and adapt. Read top‑to‑bottom or jump straight to the section that solves today’s problem.

Why Bother Searching Your Git History?

Spending minutes scrolling costs more than memorizing three commands below.

Search Commit Messages Only

Pro Tip: Combine multiple patterns with –grep/–invert-grep.

Search Code Changes (Pickaxe)

-S compares string counts between parent/child patches; -G runs a regex diff.

Once you’ve squashed the fix, branch, squash, and fork correctly before opening a pull request.

Scan the Entire History with git grep

Add -n (line numbers) or -I (skip binaries) for speed.

Narrow the Search

FlagWhat it doesExample
--authorLimit by committer--author="<[email protected]>"
--since/--untilDate range--since="2024‑01‑01"
-- path/Specific directory-- src/cli/
-iCase‑insensitive-i

Combine freely:

Quick One‑Liner Cheatsheet

Save to ~/.gitconfig under [alias] for muscle memory.

And when you’re ready to ship, see our guide on automating your deploy for zero‑downtime releases.

Visual Alternatives

  • gitk --all --grep <pattern> – lightweight GUI.
  • VS Code → Source Control panel → Search Commits extension.
  • GitHub → repository → Insights → Community → Commits and filter.

Next up → branch, squash, and fork correctly • automate your deploy.

Common Pitfalls

  1. Binary files – add -I (capital‑i) to skip.
  2. Submodules – run in each submodule or use --recurse-submodules (Git 2.13+).
  3. Large repos – prepend LC_ALL=C to speed regex; or restrict with -- path/.

That’s It—Happy Hunting

Spotted something outdated or have a faster trick? Open a PR—or better, join Gun.io and build with engineers who live in their terminal.

Gun.io

Sign up for our newsletter to keep in touch!

This field is for validation purposes and should be left unchanged.

© 2026 Gun.io