Here’s a quick guide on how to search for commits in a repository’s git commit history.

Git logs, particularly for large teams of developers, can get get massive. In such situations, scrolling through logs looking for a specific commit doesn’t really work. Here are a few ways to easily search through a repository’s git history.

Search By User

1
git log -i --author="<user>"

This command will get all the commits for users that match a specific pattern. -i will do a case insensitive search, which usually is the behavior that I want. If you are doing a search where case is important, then simply omit -i.

For example:

1
git log --author="Alan"
1
2
3
4
5
6
7
8
9
10
11
12
13
commit z14tz0ez2324251gsff5769gg67a42d543255333 (HEAD -> master, origin/master)
Author: Alan-S <myemail@something.com>
Date:   Tue Mar 31 00:44:29 2020 -0400

    Update README

commit 44ea613zzdde8b132423cczzz76abcaz9aa444gg
Author: Alan-S <myemail@something.com>
Date:   Tue Mar 31 00:43:59 2020 -0400

    Fix issue that prevents data from loading on first page load.

:

Search By String

1
git log --grep="<string>"

This command will search the commit logs for this a specific pattern and return all of the matching commits. For example, this could be useful if you want to search for a commit messages that mention a specific term or phrase.

For example:

1
git log --grep="fetch" -i
1
2
3
4
5
commit z32a231zef218R5af46ffadf253c11f40zpl7383 (HEAD -> master)
Author: Alan-Solitar <myemail@something.com>
Date:   Mon Apr 27 22:34:53 2020 -0400

    Fetch data on page load

This will grab all the logs that include the word fetch.

And that’s all. Now you should be able to more easily search through your git history. If you are interested in reading more about Git, consider checking out my article about quickly deleting all local git branches that I wrote.

Have a great day.