Video

Git Find a Commit by Its Message

Git Find a Commit by Its Message

You remember fixing a payment bug last month. But can you find that exact commit among hundreds of Git commits?

Scrolling through history to find one change is slow and frustrating. Git has a built-in answer: git log --grep, which filters commits by what their messages say.

This 2-minute explainer walks through it with a Ruby on Rails example: finding an old payment-validation fix, opening it with git show, and reading the exact lines that changed.

What you'll learn:
- What git log --grep does
- How to search commit messages by keyword
- How to ignore letter case
- How to search with multiple patterns
- How to search across all branches
- How to inspect a matching commit with git show

The commands:

# search commit messages
git log --oneline --grep="payment"

# ignore letter case
git log --oneline --grep="PAYMENT" -i

# require every pattern to match
git log --oneline --grep="payment" --grep="invoice" --all-match

# search across all refs, not just the current branch
git log --all --oneline --grep="payment"

# open the commit you found
git show b23cd45

Three things worth remembering:

1. --grep searches commit messages, not source code. Finding a change by what the code says needs a different tool.
2. With several --grep patterns, a commit matches if ANY of them matches. Add --all-match to require all of them.
3. Results are only as good as the messages. Search for "payment" and you'll miss a commit that says "Fix checkout validation" — clear commit messages are what make this work.

Chapters:

00:00 — Where Is That Commit?
00:10 — The Problem with Searching Git History
00:25 — What Is git log --grep?
00:40 — How to Search Commit Messages
01:00 — Practical Rails Example
01:25 — Benefits and Limitations
01:45 — The Takeaway

Don't scroll. Search your Git history.

#git #github #versioncontrol #gitlog #developer #programming #softwareengineering #devops #rubyonrails #coding #webdevelopment #gitcommands #codingtips #softwaredevelopment #debugging

— #Astmation —
#software #systems, #automation, and #AI-powered #applications.
Build. Automate. Evolve.
https://astmation.com/


Watch on YouTube

Back to videos