Search Git Commit History

alansolitar

Alan Solitar

Posted on May 29, 2020

Search Git Commit History

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

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:

git log --author="Alan"
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

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:

git log --grep="fetch" -i
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.

The post Search Git Commit History appeared first on Remote Dev Daily.

💖 💪 🙅 🚩
alansolitar
Alan Solitar

Posted on May 29, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What is GitHub?
github What is GitHub?

March 17, 2023

Git Commit Patterns
git Git Commit Patterns

January 27, 2023

What are your git aliases?
git What are your git aliases?

September 28, 2022