git log Filtering: --author, --since, --until, --grep, and -S (Pickaxe)
As a repository grows to hundreds or thousands of commits, scrolling through `git log` manually becomes impractical. Git provides a powerful set of filtering flags that let you search history precisely — by who made a change, when it happened, what the commit message said, or even by whether a specific piece of code was introduced or removed anywhere in history.
Learning Objectives
- Filter commits by author using --author.
- Filter commits by date range using --since and --until.
- Search commit messages using --grep.
- Find commits that introduced or removed a specific code string using -S (the pickaxe flag).
Key Terms to Know Before Learning git log Filtering
- --author: A git log flag that filters commits to only those made by an author matching the given pattern.
- --since / --until: git log flags that filter commits to a specific date range (also accepting relative values like '2 weeks ago').
- --grep: A git log flag that filters commits whose message matches a given search pattern.
- Pickaxe (-S): A git log flag that finds commits where the number of occurrences of a given string changed — i.e., commits that added or removed that exact string.
- Combined filtering: Using multiple git log flags together (e.g., --author and --since) to narrow results with several conditions at once.
How git log Filtering Actually Works
**Filtering by author** is done with `--author`, which matches against the commit author's name or email using a regular expression:
```
git log --author="Asha"
```
This returns only commits made by authors whose name or email contains 'Asha' — useful for reviewing one teammate's contributions, or auditing your own commit history on a shared project.
**Filtering by date** uses `--since` and `--until` (aliases `--after` and `--before` also work), which accept both absolute dates and Git's flexible relative date parsing:
```
git log --since="2026-06-01" --until="2026-06-30"
git log --since="2 weeks ago"
```
This is invaluable for generating a report of 'everything that happened last sprint' or investigating changes around a specific incident date.
**Filtering by commit message** uses `--grep`, which searches the commit message text (not the code changes) for a matching pattern:
```
git log --grep="login"
```
This finds every commit whose message mentions 'login' — for example, pulling together every fix and feature related to a login system, provided commit messages were written clearly (see Module 1, Lesson 10).
**The pickaxe flag (`-S`)** is different from all the above — instead of searching commit messages or metadata, it searches the actual *code changes* across history, finding every commit where the number of occurrences of a specific string changed (meaning it was added, removed, or its count changed):
```
git log -S"validateLogin"
```
This answers a very specific and powerful question: 'in which commit was this exact function name, variable, or line of text introduced or removed?' It's one of the most useful tools for tracing the origin of a specific piece of code, especially in a large, unfamiliar codebase, when you don't know which commit to look at but you do know a distinctive string that should be present.
All these flags can be combined freely, and combined with the display flags from the previous lesson (`--oneline`, `--graph`):
```
git log --author="Asha" --since="1 month ago" --grep="fix" --oneline
```
This finds every commit by Asha, in the last month, whose message mentions 'fix', displayed compactly — narrowing a potentially huge history down to exactly the handful of commits relevant to a specific question.
git log Filtering: Visual Walkthrough
Draw a funnel shape. At the wide top, label 'Full commit history (hundreds of commits)'. Show four narrowing labeled bands feeding into the funnel: '--author="Asha"', '--since="1 month ago"', '--grep="fix"', '-S"validateLogin"'. At the narrow bottom of the funnel, show a small box: 'Just 2-3 highly relevant commits'.
git log Filtering: Quick Reference Table
| Flag | Filters By | Example |
|---|---|---|
| --author=<pattern> | Commit author's name or email | git log --author="Asha" |
| --since=<date> / --until=<date> | Commit date range | git log --since="2 weeks ago" |
| --grep=<pattern> | Commit message content | git log --grep="login" |
| -S<string> (pickaxe) | Commits that changed the count of a specific string in the code | git log -S"validateLogin" |
git log Filtering: Command Syntax and Examples
# Commits by a specific author
git log --author="Asha"
# Commits within a date range
git log --since="2026-06-01" --until="2026-06-30"
# Commits in the last two weeks
git log --since="2 weeks ago"
# Commits whose message mentions 'login'
git log --grep="login"
# Commits where the string 'validateLogin' was added or removed in the code
git log -S"validateLogin"
# Combine multiple filters together, displayed compactly
git log --author="Asha" --since="1 month ago" --grep="fix" --oneline
Breaking Down the git log Filtering Example
Each command narrows history using a different criterion. `--author="Asha"` matches commit authorship metadata. `--since`/`--until` restrict results to a date window, accepting both exact dates and natural language like '2 weeks ago'. `--grep="login"` searches commit message text specifically, not code. `-S"validateLogin"` is fundamentally different — it scans the actual diffs across history to find commits that changed how many times that exact string appears, making it the tool of choice when you know a specific piece of code but not which commit introduced it. The final combined command shows how these flags stack together for very precise, multi-condition searches.
How git log Filtering Is Used on Real Engineering Teams
- Engineering managers use git log --author="name" --since="..." to generate individual contribution summaries during performance review cycles.
- Security teams use git log -S"apiKey" (pickaxe) across an entire repository's history to audit exactly when a specific credential or string was introduced or removed, which is critical during a security incident investigation.
- Support engineers investigating a regression reported by a customer often use --since and --until around the approximate time the bug appeared to narrow down a shortlist of suspicious commits.
- Release note generation scripts frequently use --grep="feat:" or --grep="fix:" (leveraging Conventional Commits, from Module 1) to automatically extract only feature or fix commits for a changelog.
git log Filtering Interview Questions and Answers
Q1. How would you find all commits made by a specific person in the last month?
Combine --author and --since flags: git log --author="name" --since="1 month ago". This filters the history to only commits authored by that person within the specified date range.
Q2. What is the pickaxe flag (-S) in git log, and how is it different from --grep?
-S searches the actual code changes in each commit's diff, finding commits where the number of occurrences of a specific string changed — meaning it was added or removed. --grep, in contrast, searches only the commit message text, not the code itself. They answer fundamentally different questions: --grep finds commits described a certain way; -S finds commits that touched specific code.
Q3. How would you use git log to find when a specific function name was introduced into the codebase?
Use the pickaxe flag with that function name as the search string: git log -S"functionName". This searches every commit's diff for a change in how many times that exact string appears, pinpointing the commit where it was first added (or later removed).
git log Filtering Quiz: Test Your Understanding
1. Which git log flag filters commits based on who authored them?
- --grep
- --author
- --since
- -S
Answer: B. --author
Explanation: --author filters the commit history to only show commits whose author name or email matches the given pattern.
2. What does git log --grep="login" search?
- The actual code changes in each commit
- The commit message text
- The author's email address
- File names changed in each commit
Answer: B. The commit message text
Explanation: --grep searches specifically within commit messages for a matching pattern, not the underlying code changes.
3. What does the pickaxe flag (-S) in git log search for?
- Commits within a specific date range
- Commits where a specific string's occurrence count changed in the code
- Commits made by a specific author
- Commits tagged with a specific release version
Answer: B. Commits where a specific string's occurrence count changed in the code
Explanation: The pickaxe flag (-S) searches the actual diffs across history for commits where a given string was added or removed, changing its occurrence count.
4. Which flags would you combine to find commits by 'Rohit' in the last two weeks whose message mentions 'bug'?
- --author="Rohit" --since="2 weeks ago" --grep="bug"
- -S"Rohit" --grep="2 weeks"
- --grep="Rohit" -S"bug"
- --since="Rohit" --author="bug"
Answer: A. --author="Rohit" --since="2 weeks ago" --grep="bug"
Explanation: Combining --author, --since, and --grep applies all three conditions together, narrowing results to commits matching author, date range, and message content simultaneously.
git log Filtering: Common Mistakes Beginners Make
- Confusing --grep (searches commit messages) with -S (searches actual code changes) — they answer entirely different questions.
- Expecting --author to require an exact full name match, when it actually matches as a pattern against name or email, so partial matches work.
- Forgetting that --since and --until accept natural language like '2 weeks ago', not just exact calendar dates.
- Using -S without realizing it searches for changes in occurrence count, not just 'any commit that mentions this string anywhere' (a string present in every version of a file won't show up).
git log Filtering: Exam-Ready Quick Notes
- --author filters by commit author (name/email pattern match).
- --since / --until filter by date range, accepting relative or absolute dates.
- --grep filters by commit message content.
- -S (pickaxe) filters by commits that changed how many times a specific string appears in the code.
git log Filtering: Key Takeaways
- Git log filtering flags turn an unmanageable wall of history into precisely the handful of commits relevant to your question.
- --author, --since/--until, and --grep filter based on commit metadata and messages; -S (pickaxe) uniquely filters based on actual code content changes.
- These flags combine freely, letting you build highly specific searches across large, long-lived repositories.
Frequently Asked Questions About git log Filtering
Q1. How do I find all commits made by a specific person?
Use git log --author="name", which filters the commit history to only show commits whose author name or email matches the given pattern.
Q2. How can I see only commits from the last two weeks?
Run git log --since="2 weeks ago". Git understands natural relative date expressions like this, as well as exact dates such as --since="2026-06-01".
Q3. What is the difference between --grep and -S in git log?
--grep searches commit message text for a matching pattern. -S (the pickaxe flag) instead searches the actual code changes across history, finding commits where a specific string's occurrence count changed — meaning it was added or removed somewhere in the diff.
Q4. How do I find the exact commit where a specific function or variable was introduced?
Use the pickaxe flag: git log -S"functionOrVariableName". This scans every commit's diff for a change in how many times that exact string appears, pinpointing when it was added or removed.
Q5. Can I combine multiple git log filters at once?
Yes. Flags like --author, --since, --until, and --grep can all be combined in a single command, letting you narrow history down using several conditions simultaneously, such as git log --author="Asha" --since="1 month ago" --grep="fix".
Summary
Git provides several powerful flags to filter `git log` output precisely: `--author` matches commits by author name or email, `--since`/`--until` restrict results to a date range (accepting both absolute and relative dates), and `--grep` searches commit message text for a pattern. The pickaxe flag, `-S<string>`, is fundamentally different — it searches the actual code changes across history, finding commits where a specific string's occurrence count changed, making it invaluable for tracing exactly when a piece of code was introduced or removed. These flags can be freely combined to build highly targeted searches through even very large repository histories.