The Hook (The "Byte-Sized" Intro)
git log with no filters is like searching Google without a query — you get everything and find nothing useful. But add --author, --since, --grep, and suddenly 10,000 commits narrow to the 3 you care about. Mastering log filters turns Git history from a firehose into a precision tool.
📖 What are git log Filters?
Filters let you narrow git log output by criteria like author, date, message content, file path, and more.
Conceptual Clarity
Filter reference:
| Filter | Flag | Example |
|---|---|---|
| By author | --author | --author="Jane" |
| By date (since) | --since | --since="2026-01-01" |
| By date (until) | --until | --until="2 weeks ago" |
| By message | --grep | --grep="login" |
| By file | -- <path> | -- src/auth.js |
| Limit count | -n | -5 (last 5) |
| No merges | --no-merges | Skips merge commits |
| First parent only | --first-parent | Linear main history |
Format options:
| Format | Flag | Use Case |
|---|---|---|
| One line | --oneline | Quick overview |
| Graph | --graph | Branch visualization |
| Custom | --format="%h %an %s" | Scripting |
| Stat | --stat | Files changed summary |
| Patch | -p | Full diff per commit |
Real-Life Analogy
Log filters are like email inbox search. --author is "from:", --since is "after:", --grep is keyword search. Without filters, you scroll forever. With them, you find the email in seconds.
Visual Architecture
Why It Matters
- Speed: Find specific commits in seconds, not minutes of scrolling.
- Precision: Combine filters for extremely targeted searches.
- Reporting: Generate changelogs and statistics from filtered logs.
- Debugging: Narrow the investigation window rapidly.
Code
# ─── Filter by author ───
git log --author="Jane" --oneline -10
# ─── Filter by date range ───
git log --since="2026-01-01" --until="2026-02-01" --oneline
# ─── Filter by commit message ───
git log --grep="fix" -i --oneline
# -i makes it case-insensitive
# ─── Filter by file ───
git log --oneline -- src/auth.js
# ─── Combine filters ───
git log --author="Jane" --since="2 weeks ago" \
--grep="login" --oneline -- src/auth.js
# ─── Show files changed per commit ───
git log --stat -5
# ─── Custom format for scripting ───
git log --format="%h | %an | %ar | %s" -10
# ─── Skip merge commits ───
git log --no-merges --oneline -20Key Takeaways
- Combine
--author,--since,--grep, and-- pathfor precise searches. --onelinefor quick scans,--statfor file summaries,-pfor full diffs.- Filters can be combined — they're ANDed together for precise results.
--formatenables custom output for scripting and reporting.
Interview Prep
-
Q: How do you find all commits by a specific author in the last month? A:
git log --author="name" --since="1 month ago" --oneline. You can further narrow by adding-- <path>for a specific file or--grepfor a message keyword. -
Q: What is
--first-parentand when would you use it? A:--first-parentfollows only the first parent of merge commits, showing the linear history of the main branch. Useful for seeing what was merged (as merge commits) without diving into feature branch details. -
Q: How do you search commit messages for a keyword? A:
git log --grep="keyword" --oneline. Add-ifor case-insensitive search. The search is applied to the commit message content.