Lesson Completion
Back to course

git log Filters

Beginner
8 minutes4.7Git

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:

FilterFlagExample
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-mergesSkips merge commits
First parent only--first-parentLinear main history

Format options:

FormatFlagUse Case
One line--onelineQuick overview
Graph--graphBranch visualization
Custom--format="%h %an %s"Scripting
Stat--statFiles changed summary
Patch-pFull 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

flowchart TD LOG["git log"] --> AUTHOR["--author"] LOG --> DATE["--since / --until"] LOG --> MSG["--grep"] LOG --> FILE["-- path"] LOG --> FORMAT["--oneline / --graph"] style LOG fill:#0f3460,stroke:#53d8fb,color:#53d8fb

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

bash
# ─── 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 -20

Key Takeaways

  • Combine --author, --since, --grep, and -- path for precise searches.
  • --oneline for quick scans, --stat for file summaries, -p for full diffs.
  • Filters can be combined — they're ANDed together for precise results.
  • --format enables 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 --grep for a message keyword.

  • Q: What is --first-parent and when would you use it? A: --first-parent follows 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 -i for case-insensitive search. The search is applied to the commit message content.

Topics Covered

Git HistorySearch

Tags

#git#log#filters#search

Last Updated

2026-02-13