Open In App

How to Search Git Repository By Commit Message?

Last Updated : 21 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Searching a Git repository by commit message can be incredibly useful for tracking changes, identifying specific updates, or understanding the history of a project. Git provides several ways to search for commit messages via the command line.

Using Git Log with Grep

This approach involves using the git log command combined with grep to search through commit messages for specific keywords or phrases. It is a straightforward and powerful method for finding commits that match a certain pattern.

Syntax

git log --grep="search-term"

Example: This example searches for commits with the message containing "Initial".

git log --grep="Initial"
Screenshot-2024-06-05-184433
How to Search Git Repository By Commit Message

Searching All Branches

To search commit messages across all branches, you can use the --all flag with the git log command. This is useful when the commit might not be in the current branch.

Syntax

git log --all --grep="search-term"

Example: This example searches for the term "refactor" in commit messages across all branches.

git log --all --grep="Initial"
Screenshot-2024-06-05-184707
How to Search Git Repository By Commit Message?

Next Article
Article Tags :

Similar Reads