Git Log Filters: Find Changes by File or Author
Find the relevant file history
Filter a long history to find commits relevant to a specific task. Start with the same clean three-commit fixture. A path filter limits the history shown; merge history simplification can affect results in complex graphs.
The notes query lists Replace rice with milk and Add notes; the README query lists Add project readme. A path filter is not a text search inside a file. --follow can trace one file across detected renames, but is not a complete history reconstruction for every graph.
Filter author, message and date
--author matches author metadata using a pattern, while --grep searches commit messages. Neither proves who actually operated the keyboard. --since and --until filter by commit (committer) timestamps; use explicit times and zones to avoid ambiguous local dates.
git log --oneline --author="Lab Reviewer"git log --oneline --grep="milk"git log --oneline --since="2025-01-02T00:00:00Z" --until="2025-01-02T23:59:59Z"The first query finds Add project readme; the other two find Replace rice with milk in this fixture. Author and committer dates can differ; timestamp filters are not a guarantee of graph topology.
Pick a useful output format
Use --stat for counts and --name-status for changed paths. Limit output to the latest relevant commit using -1. Add --format=%s when only the subject is useful; human-readable log layouts can vary by configuration.
git log -1 --stat -- notes.txtgit log -1 --format=%s --name-status -- notes.txtThe first shows the milk commit with one insertion and deletion; the second gives its subject and M notes.txt (separated by a tab). Combine filters when investigating a real issue rather than reading unrelated history.
Practice and next step
Find the last notes.txt commit by ByteMind Learner whose message contains milk. Then inspect it using git show and confirm the repository is still clean. Next chapter teaches renaming, removal and ignore rules.
git log -1 --oneline --author="ByteMind Learner" --grep="milk" -- notes.txtgit status --shortThe matching commit is Replace rice with milk; status has no output. If there are no matches, loosen one filter at a time; a blank log does not prove a change never existed.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Log Filters: Find Changes by File or Author — knowledge check
Interpret Git history and differences using the chapter fixture.
Which command finds history for notes.txt?
Which filter searches commit messages for milk?
Which filter selects the fictional author Lab Reviewer?
Which date is used by --since and --until?
What is a sensible response to an unexpectedly empty filtered log?