How to Filter Git Log History

To filter Git history, add options to git log: --author for who, --since and --until for when, --grep for words in the commit message, -S for code that was added or removed, and -- <path> for a file or folder. They combine, and --oneline keeps the output to one line per commit.

Run these in the repository folder. The examples use a small demo repository; change the names, dates and words to yours.

By Author

Bash
git log --oneline --author="Alex"

--author matches part of the name or email, so "Alex" also finds Alex Morgan. Who wrote what across the whole history is in Git Log by Author.

By Date

Bash
git log --oneline --since="2 weeks ago"
git log --oneline --since="2026-11-01" --until="2026-11-15"

--since and --until take a date or plain English like "yesterday" or "3 days ago". They filter on the commit date.

By Commit Message

Bash
# commits whose message mentions "import"
git log --oneline --grep="import"

# case-insensitive
git log --oneline -i --grep="fix"

By Code That Changed

Bash
# commits that added or removed this exact text anywhere in the code
git log --oneline -S "connectionTimeout"

This is the one to use when you want to know when something appeared in, or disappeared from, the code. --grep only searches the messages; -S searches the changes themselves.

By File or Folder

Bash
# only commits that touched this file (the -- separates paths from options)
git log --oneline -- src/import.ps1

# a whole folder
git log --oneline -- docs/

Combining Filters

Bash
git log --oneline --author="Sam" --grep="import" --since="1 month ago"

Different kinds of filter combine as AND: that line only shows Sam’s commits that mention “import” from the last month. The exception is repeating --grep: 2 of them match a message containing either word. Add --all-match to need both:

Bash
# either word
git log --oneline --grep="import" --grep="retry"

# both words
git log --oneline --grep="import" --grep="retry" --all-match
git log filtering by author, by message with two --grep patterns, and with --all-match so both words must appear

A Readable Format for the Results

Bash
# hash, date, author and message on one line
git log --format="%h %ad %an %s" --date=short --since="2 weeks ago"

# leave out merge commits, and stop after 10
git log --oneline --no-merges -n 10

More on the one-line view and the branch graph is in Git Log One Line.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *