How to Search Git History with git log Filters
In this tutorial, you'll learn about How to Search Git History with git log Filters. We cover key concepts, practical examples, and best practices.
The Problem
You need to find a specific commit in Git history but git log shows too many entries. Searching through hundreds of commits manually is slow and error-prone.
Quick Fix
Step 1: Search commit messages with --grep
Find commits whose message contains a keyword:
git log --grep="fix login" --oneline
a1b2c3d Fix login validation in auth module
e5f6g7h Add login page error handling
Step 2: Filter by author
Find all commits by a specific person:
git log --author="alice" --oneline
a1b2c3d Fix login validation in auth module
i8j9k0l Add login page component
Step 3: Filter by date range
Commits from the last 7 days:
git log --since="7 days ago" --oneline
Commits between two dates:
git log --after="2026-06-01" --before="2026-06-15" --oneline
Step 4: Show commits that changed a specific file
See all commits that modified a given file:
git log --oneline src/auth/login.ts
a1b2c3d Fix login validation in auth module
i8j9k0l Add login page component
Step 5: Combine multiple filters
Narrow down with several criteria at once:
git log --author="bob" --since="2026-06-01" --grep="database" --oneline
Step 6: Show changes in each commit
Add -p to see the actual diff:
git log --author="alice" --oneline -p -- src/auth/
Step 7: Visualize the commit graph
View the branch structure alongside the log:
git log --graph --oneline --all
* a1b2c3d Merge branch 'feature/login'
|\
| * i8j9k0l Add login page component
* | e5f6g7h Fix main branch bug
|/
* 8f9g0h1 Initial commit
Alternative Solutions
Search code in historical commits
Use git log -S to find commits that added or removed a specific string:
git log -S "apiKey" --oneline
Pickaxe search with regex
Search with a regular expression across all commits:
git log -G"function.*login" --oneline
Common Mistakes to Avoid
Forgetting --oneline for readability. Without --oneline, each commit shows the full message, hash, author, and date, making it hard to scan.
Using --grep without --all to search all branches. By default, git log --grep only searches the current branch. Use --all to search every branch.
Not quoting multi-word grep patterns. git log --grep=fix bug searches for "fix" only. Use git log --grep="fix bug" for the full phrase.
Pro Tips
Use git shortlog for contributor summaries. git shortlog -sn shows a sorted list of authors and commit counts for release notes.
Use git log --diff-filter for specific changes. --diff-filter=A shows only added files, --diff-filter=D shows only deleted files.
Use git log -p with --word-diff. For word-level diffs instead of line-level: git log -p --word-diff --since="2026-01-01".
Prevention
- Write descriptive commit messages so
--grepsearches are effective. - Use consistent author names across all commits.
- Make small, focused commits to keep
git logoutput meaningful.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro