By admin , 29 April 2026

Synopsis

git log [<options>] [<revision-range>] [[--] <path>...]

Description

The git log command displays the commit history reachable from one or more refs (defaulting to HEAD). It is one of the most flexible tools in Git, supporting filtering by author, date, message content, file paths, and more. Combined with formatting options, it can produce output suitable for changelogs, audits, and code archaeology.

Useful idioms include git log --oneline --graph --decorate --all for a compact, visual view of the entire history, and git log -p to see patches inline. Pathspec arguments restrict the log to commits that touched specific files.

In day-to-day use, git log integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git log --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.

Understanding how git log interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git log's side effects helps avoid all three.

Common Options

OptionDescription
--onelineOne commit per line, abbreviated SHA + subject.
--graphASCII art of branch and merge structure.
--allInclude all refs, not just HEAD.
-p, --patchShow diffs alongside each commit.
--statShow changed-file statistics.
--author=<pattern>Filter by author.
--since / --untilFilter by date.
-S <string>Pickaxe: find commits that add/remove this string.
--followTrack a single file's history across renames.

Examples

git log --oneline --graph --decorate --all
# Compact visual history of everything

git log -p src/auth.py
# Full diffs of every commit touching auth.py

git log -S "TODO" --since="2 weeks ago"
# Find recent commits that added or removed "TODO"

git log --author="alice" --pretty=format:"%h %s" -n 20
# Last 20 commits by alice in custom format

Common Mistakes

Forgetting that git log file.txt only shows commits where file.txt existed — use --follow if it has been renamed. Over-relying on --grep when you really want -S (which searches diffs, not messages). And on huge repos, git log -p without a path can produce gigabytes of output.

Related Commands

git show, git blame, git shortlog, git diff