How to Search Git Logs by Commit Message |Video upload date:  · Duration: PT2M23S  · Language: EN

Search Git commit messages with git log grep and useful flags to find commits fast from the command line

Need to find that one commit that fixed a bug or introduced chaos and you do not want to read the entire history by candlelight? Use git log and grep like a civilized developer. This guide shows practical commands and small bits of sarcasm to keep you awake while you search commit messages in version control from the CLI.

Search by message text with --grep

The simplest trick is to let git filter commit messages for you. The --grep flag matches the commit message text with a regular expression. It is fast and often all you need.

git log --grep='fix crash'

That returns commits whose messages match the pattern. No witchcraft, just grep style matching built into git log.

Ignore case when people are inconsistent

People type commit messages in ALL CAPS, Title Case, and weird emoji hieroglyphs. Use -i to make your search case insensitive.

git log -i --grep='memory leak'

Now Fix Memory Leak and fix memory leak are equals. Peace at last.

Search all branches and tags

If the commit is hiding on another branch or a tag please do not assume it will come to you. Use --all to search everywhere.

git log --all --grep='refactor'

This covers branches and tags so there is no accidental tunnel vision.

Make output compact for fast scanning

When history gets chatty use a compact view so you can scan results quickly.

git log --pretty=oneline --grep='typo'

One line per commit shows the hash and message so you can eyeball the candidate commits without squinting.

Limit the number of results

If the history spits out a novella add -n to cap the results to the most recent matches.

git log -n 5 --grep='add tests'

This shows the latest five matches and spares you from scrolling forever.

Combine flags for a focused search

Mix and match the options to suit your workflow. Here is a typical combination that is both practical and slightly smug.

git log --all -i --pretty=oneline -n 10 --grep='bug fix'

That searches every ref with case insensitive matching, shows concise results, and limits output to the ten most recent hits. Efficient and tidy.

When to use git log -S

If you want to find commits that changed the code rather than the commit message try git log -S. It looks for changes in the patch text rather than the message. That matters when the message is useless and the code tells the truth.

git log -S 'calculateTotal' --pretty=oneline

Filter by author when that helps

Sometimes knowing who wrote the commit narrows things down. Use --author to filter by committer or author name.

git log --author='Alex' --grep='perf'

Quick checklist

  • Use --grep to search message text
  • Add -i for case insensitive matches
  • Add --all to search all branches and tags
  • Use --pretty=oneline for compact output
  • Use -n to limit the number of results
  • Use -S to search code changes instead of messages
  • Use --author to narrow results by committer

If you remember one thing let it be this. Search with --grep and tune with -i --all --pretty and -n until the result set looks human sized. That will save you time and dignity. Now go find the commit and pretend you always knew where it was.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.