Course contentsShow
← Data Science
Lesson 2000 of 2,14546. Version Control with GitFree lesson

Formatting and Filtering Log Output

Customize `git log` with options like `--oneline`, `--graph`, and `--author` to filter and format history.

Formatting and Filtering Log Output

You'll learn how to customize git log to display exactly the commit history you need, in a format that makes sense for your workflow.

The Core Idea

After learning to view commit history with git log, you've probably noticed the output can be verbose and overwhelming, especially in projects with hundreds of commits. Git provides powerful options to filter which commits you see and format how they're displayed. Think of it like having a library catalog with advanced search filters and different viewing modes—sometimes you want full book descriptions, other times just titles and authors.

Common Formatting Options

git log --oneline condenses each commit to a single line showing abbreviated hash and message—perfect for a quick overview.

git log --graph draws a text-based visual representation of branch structure, showing how commits connect. Combine with --oneline for a compact branch visualization: git log --oneline --graph.

git log --stat shows which files changed in each commit and how many lines were added/removed.

Filtering Your History

git log --author="Jane" shows only commits by authors matching "Jane"—useful when tracking contributions or reviewing your own work.

git log -n 5 limits output to the last 5 commits (replace 5 with any number).

git log --since="2024-01-01" or git log --after="2 weeks ago" filters by date—great for weekly reviews or finding when changes occurred.

git log -- filename.py shows only commits that modified a specific file.

Combining Options

You can combine these options for laser-focused queries: git log --oneline --author="Jane" --since="1 week ago" shows Jane's recent commits in compact form.

Key Takeaway: Mastering git log formatting and filtering transforms commit history from an overwhelming list into a precise research tool, letting you quickly find relevant changes by author, date, file, or branch structure.