Skip to content
February 27, 2017 · 1 min read

How to do a Git log search

So, you want to search your git commit logs. Good news! It’s really easy to find something in your git log, and I’m going to show you how to do it.

If you use git, you’re probably already familiar with the classic UNIX string searching tool, ‘grep.’ (If you already know about grep but want something better, you should try out Ack, but that’s an unrelated issue.)

Lucky for you, git has a ‘grep’ mode that’s perfect for doing a git log search!

Suppose I wanted to search for the string “facebook” in all of the commit messages of my project. All it takes is this one command:

git log --grep="facebook"

and you’ll see all of the log messages which contain the our search term!

Okay, now suppose that you want to search more than just the commit messages, but the commits themselves. Simple! Drop the ‘log’ argument.

git grep "facebook" $(git rev-list --all)

This will show the commit ID and line number of all instances of your string. (The string can also be a regular expression, which is handy if you know regex, too.)

This can be made slightly more human-friendly by using the ‘pickaxe’ feature of git log grep, like this:

git log -S"facebook"

which will show all the commit messages of commits which include your string.

Hope this helped!