git log: Master Commit History Navigation and Filtering

Find everyday Git history with practical filters for authors, dates, files, and code changes; choose a command by the question you need to answer.

published: reading time: 14 min read author: Geek Workbench updated: November 17, 2026
Quick Summary

Use git log to inspect reachable commits, filter by author, date, path, or changed text, and compare ranges. A task-based command chooser points to blame, commit history, bisect, and reflog when the question needs a different view.

Introduction

git log is your window into the repository’s history. Every commit, every branch point, every merge — it is all there, waiting to be queried. But the default git log output is just the tip of the iceberg. Git’s log command supports dozens of formatting options, powerful filters, and search capabilities that turn your commit history into a searchable database.

Most developers use git log as a simple list of recent commits. Power users use it to find exactly when a bug was introduced, track who changed a specific function, visualize branch topology, audit compliance, and generate release notes. The difference is not in the tool — it is in knowing which flags to combine.

This guide covers every important form of git log, from basic usage to advanced filtering, searching, and visualization. Mastering these techniques makes you a Git historian who can answer any question about your repository’s past. For understanding commit creation, see git commit.

Choose a History Question

Question Start here Then inspect
Who last changed this line? git blame -L Open the commit and review its parent diff; blame is a starting point, not proof of intent.
When did this string or behavior change? git log -S 'text' -- path or git log -G 'pattern' -- path Review the matching commit with git show.
What changed between two releases or branches? git log base..head --oneline Add --stat or -p to inspect the affected files and patch.
How did a file evolve, including a rename? git log --follow -p -- path Compare the relevant commits and their diffs.
Did a local reset or rebase move a ref away from a commit? git reflog Create a rescue branch if the object still exists; reflog is local and expires.

git log follows commits reachable from the starting refs you name. It does not list every object in the repository. git reflog records previous values of local refs, so it can point to commits that git log no longer reaches; expiry and pruning can remove that recovery path. See the reflog recovery guide before moving a ref.

When to Use / When Not to Use

Use git log when:

  • Finding when a bug was introduced using git log -S or git log -G
  • Understanding the history of a specific file or directory
  • Reviewing what changed between releases or tags
  • Auditing who made what changes and when
  • Visualizing branch structure and merge patterns
  • Generating changelogs or release notes

Use specialized tools instead when:

  • You need to see the actual code changes — use git diff or git show
  • You need to interactively walk through history — use git reflog
  • You need to find which commit broke something — use git bisect
  • You need to see file-level changes — use git log --follow for renames

Core Concepts

git log walks the commit graph starting from the specified commit(s) (default: HEAD) and outputs information about each commit. It follows parent pointers, so it naturally traverses the entire history reachable from the starting point. The output format, filtering, and sorting are all configurable.


graph TD
    A[HEAD] --> B[git log reads commit graph]
    B --> C[Applies filters]
    C --> D[Formats output]
    D --> E[Displays results]

    C --> C1[By author]
    C --> C2[By date range]
    C --> C3[By message content]
    C --> C4[By file path]
    C --> C5[By code changes]

    D --> D1[One line]
    D --> D2[Full message]
    D --> D3[With diff]
    D --> D4[Custom format]
    D --> D5[Graph visualization]

The Commit Graph


graph LR
    A[A] --> B[B]
    B --> C[C]
    C --> D[D]
    C --> E[E]
    D --> F[F]
    E --> F

The commit graph is the data structure Git uses to represent history. Every commit (except the very first) stores a reference to one or more parent commits — the commits that came directly before it. When you run git log, Git starts at your current position (HEAD) and follows those parent pointers backward through time, building a list of commits in reverse chronological order.

This parent-pointer structure is what makes git log different from a simple file of entries. Because commits can have multiple parents (merge commits) or zero parents (the initial commit), the history forms a directed acyclic graph (DAG) rather than a straight line. The diagram above shows this: commit F is HEAD, and both D and E point to F as their parent, meaning they were merged into the main line together.

When a commit has two parents, it is a merge commit — Git records both lineages and the log naturally walks both branches. You can control how Git handles this branching with flags like --topo-order (groups same-branch commits together) or --first-parent (follows only the first parent, ignoring merged branch commits). Understanding the graph structure is foundational to reading git log output correctly, especially when interpreting merge-heavy histories.

Architecture or Flow Diagram

git log Filter Pipeline


graph LR
    A[All Commits<br/>from HEAD] --> B{Author Filter}
    B -->|match| C{Date Filter}
    B -->|skip| A
    C -->|match| D{Message Filter}
    C -->|skip| A
    D -->|match| E{File Filter}
    D -->|skip| A
    E -->|match| F{Code Search}
    E -->|skip| A
    F -->|match| G[Format Output]
    F -->|skip| A

Each filter in the pipeline is independent and optional — Git applies them in sequence, and a commit must pass every active filter to appear in the output. This is the key mental model: think of git log not as a single command but as a commit stream that gets progressively refined. You can apply zero filters (all commits from HEAD), or stack as many as you need.

The pipeline order matters for performance. Author and date filters are evaluated first because they reject the most commits early, avoiding unnecessary work on commits that would be filtered later. Message and path filters come next, and the code-search pickaxe (-S / -G) runs last because it requires parsing diff content, which is the most expensive operation. If you are working with a large repository and queries are slow, adding a date or author constraint early dramatically reduces the search space.

This pipeline structure also explains why some combinations behave unexpectedly. For example, --grep and --author filter different fields independently — a commit matching the author filter but not the message filter is still excluded. Combining -S with --grep means a commit must pass both tests. Understanding the sequential nature of the pipeline prevents surprises when building complex queries.

Output Format Options


graph TD
    A[git log] --> B[Default<br/>Full commit info]
    A --> C[--oneline<br/>Hash + message]
    A --> D[--stat<br/>File change summary]
    A --> E[--graph<br/>ASCII branch graph]
    A --> F[--format<br/>Custom template]
    A --> G[--patch<br/>With diff content]

    B --> H[Best for: detailed review]
    C --> I[Best for: quick overview]
    D --> J[Best for: impact assessment]
    E --> K[Best for: branch visualization]
    F --> L[Best for: custom reports]
    G --> M[Best for: code review]

The format you choose changes what information is available for downstream processing. --oneline is the most common choice for human readability — it truncates the hash and message to fit a terminal width. --stat shows which files changed and by how much, making it useful for impact assessment without reading individual diffs. --patch (or -p) shows the full diff content, which is what you want for code review but produces verbose output on large histories.

For automation and scripting, --format is the most powerful option. It accepts a template string with named placeholders — %h for abbreviated hash, %an for author name, %ae for author email, %ad for author date, %s for subject line, %b for body. You can combine these arbitrarily and even add literal text: --format="%h %an %ad: %s". Color placeholders like %C(yellow) and %C(reset) make output easier to scan in terminal environments. The --date flag controls the date format used by %ad — common values are short (2026-03-31), iso (2026-03-31 14:30:00 +0530), and relative (2 weeks ago).

For CI/CD pipelines and compliance reporting, --name-only or --name-status produce machine-parseable output without formatting overhead. --name-status includes a single-letter status code before each filename: M for modified, A for added, D for deleted, R for renamed. This is the format to reach for when feeding commit data into external tools or generating structured audit logs.

Step-by-Step Guide / Deep Dive

Getting Started with Git Log

Most git log calls answer one of three questions: what changed, who changed it, or when it happened. The commands below are the ones you will reach for daily — grouped by what they help you do.

Run the default first to get your bearings, then tighten the query as your question becomes more specific. -5 to limit to recent commits, --stat when you need to gauge impact. That already puts you ahead of most developers who never go past the defaults.

Core Git Log Operations

Log Output and Commit Identification


# Default log output
git log

# Compact one-line per commit
git log --oneline

# Show only the last N commits
git log -5
git log -n 10

File Change Statistics


# Show files changed per commit
git log --stat

# Show number of files changed
git log --shortstat

# Show only file names
git log --name-only

# Show file names with status (A/M/D/R)
git log --name-status

# Custom stat format
git log --stat --stat-width=80

Advanced Combinations


# All commits by Jane in the last month touching Python files
git log --author="Jane" --since="1 month ago" -- "*.py"

# Find when a function was introduced
git log -S "def calculate_total" --oneline -- src/

# Visualize feature branch history
git log --oneline --graph --all --grep="feat:"

# Audit all changes to a sensitive file
git log --follow --format="%h %an %ad %s" --date=short -- src/config.py

# Generate changelog between releases
git log v1.0.0..v2.0.0 --oneline --no-merges

Commit Filtering Options

Filtering Commits

Git’s commit graph is a directed acyclic graph — every commit points backward to its parents, forming a chain that stretches to the initial commit. When you filter commits, you are not deleting anything from the repository; you are telling Git which subset of the graph to walk and display. Filters stack in a pipeline, so think of building a query by adding constraints one after another.

Author, date, message content, file path, and code change are the main filters. Each operates independently — a commit must pass every active filter to appear in output. So --author="Jane" --grep="fix" means a commit must match both conditions, not either one.

By Author and Date

# Commits by a specific author
git log --author="Jane"

# Commits NOT by a specific author
git log --author="Jane" --invert-grep

# Case-insensitive author search
git log --author="jane" -i
By Message and Path

# Commits whose message contains a keyword
git log --grep="authentication"

# Commits that touched a specific file
git log -- src/app.py

# Follow file across renames
git log --follow -- src/app.py

Range Comparisons Between Branches and Tags


# Commits reachable from feature but not from main
git log main..feature

# Commits reachable from either but not both (symmetric difference)
git log main...feature

# Commits between two tags
git log v1.0.0..v2.0.0

# Commits since a tag
git log v1.0.0..HEAD

Code Change Search with Pickaxe


# Commits that added or removed a specific string
git log -S "function_name"
git log -S "API_KEY"

# Commits that added or removed a regex pattern
git log -G "def\s+\w+\("

# The difference: -S looks for exact string count changes, -G looks for regex matches in diff
# -S "foo" finds commits where the number of "foo" occurrences changed
# -G "foo.*bar" finds commits where any diff line matches the regex

Formatting Options


# Pretty formats
git log --oneline           # abc1234 feat: add auth
git log --short             # Short hash + author + date + message
git log --medium            # Default format
git log --full              # Full message with full headers
git log --fuller            # Both author and committer info

# Custom format with placeholders
git log --format="%h %s"                           # Hash + subject
git log --format="%h %an %ar %s"                   # Hash + author + relative date + subject
git log --format="%C(yellow)%h %C(reset)%s"         # Colored output
git log --format="%H%n%an%n%ae%n%ad%n%s"           # Multi-line detailed

# Common placeholders:
# %H - Full commit hash
# %h - Abbreviated commit hash
# %an - Author name
# %ae - Author email
# %ad - Author date (respects --date format)
# %ar - Author date, relative
# %s - Subject (first line of message)
# %b - Body
# %D - Ref names (branches, tags)

Visualizing Branch Structure


# ASCII graph of branch topology
git log --oneline --graph

# Show all branches
git log --oneline --graph --all

# Show all branches with decoration (branch/tag labels)
git log --oneline --graph --all --decorate

# The ultimate alias
git log --oneline --graph --all --decorate --color

Output:


* abc1234 (HEAD -> main) feat: add user profile
| * def5678 (feature/auth) fix: handle token expiry
| * ghi9012 feat: add JWT authentication
|/
* jkl3456 (tag: v1.0.0) Release v1.0.0
* mno7890 Initial commit

Filtering by Author


# Commits by a specific author
git log --author="Jane"
git log --author="jane@example.com"

# Commits NOT by a specific author
git log --author="Jane" --invert-grep

# Case-insensitive author search
git log --author="jane" -i

Filtering by Date


# Commits since a date
git log --since="2026-01-01"
git log --after="2026-01-01"

# Commits before a date
git log --until="2026-03-01"
git log --before="2026-03-01"

# Relative dates
git log --since="2 weeks ago"
git log --since="3 months ago"
git log --after="yesterday"

# Date range
git log --since="2026-01-01" --until="2026-03-31"

Filtering by Message Content


# Commits whose message contains a keyword
git log --grep="authentication"
git log --grep="fix" --oneline

# Case-insensitive search
git log --grep="AUTH" -i

# Multiple keywords (OR by default)
git log --grep="auth" --grep="login"

# Multiple keywords (AND)
git log --all-match --grep="auth" --grep="token"

# Regular expression search
git log --grep="^feat:" --oneline

Filtering by File Path


# Commits that touched a specific file
git log -- src/app.py

# Commits in a directory
git log -- src/

# Commits that touched any of multiple files
git log -- src/app.py src/utils.py

# Follow file across renames
git log --follow -- src/app.py

# Show only commits that changed files matching a pattern
git log -- "*.py"

Searching Code Changes


# Commits that added or removed a specific string
git log -S "function_name"
git log -S "API_KEY"

# Commits that added or removed a regex pattern
git log -G "def\s+\w+\("

# The difference: -S looks for exact string count changes, -G looks for regex matches in diff
# -S "foo" finds commits where the number of "foo" occurrences changed
# -G "foo.*bar" finds commits where any diff line matches the regex

Comparing Ranges


# Commits reachable from feature but not from main
git log main..feature

# Commits reachable from either but not both (symmetric difference)
git log main...feature

# Commits between two tags
git log v1.0.0..v2.0.0

# Commits since a tag
git log v1.0.0..HEAD

Continue with deeper history work

This page covers everyday git log queries. For regression searches, audit trails, and failure scenarios, continue to Git log forensics. For line-level attribution, see Git blame; for recovering a moved or deleted ref, see Git reflog recovery.

Further Reading

Conclusion

Use the smallest query that answers your history question. Add a patch or stat view when a commit needs closer inspection, and use the forensics guide when everyday filters are not enough.

Category

Related Posts

Git Log Forensics: Bisect, Audits, and Recovery

Use Git history for regression searches, audits, and recovery. Learn bisect limits, code-change searches, and how reachable commits differ from reflog entries.

#git #git-log #history

Git Bisect: Bug Hunting with Binary Search

Master git bisect to find the exact commit that introduced a bug using binary search. Automate bug hunting with scripts and handle complex scenarios.

#git #version-control #debugging

Git Blame and Annotate: Line-by-Line Code Attribution

Master git blame for line-by-line code attribution, understanding code history, finding when code changed, and using blame effectively for code comprehension.

#git #version-control #git-blame