All commands

git log

Walk the chain of parent links and read your history.

What it does

git log is a pure read operation: starting from HEAD, it follows each commit's parent pointer to the previous commit, forever. Every commit object is rendered as a line (or more) of metadata and its message. None of it touches your working tree.

9a2f1c0init project4b7c2a5add componentsc86d9eestyle layoute1b5a09fix nav menu74d3b9ffeat: dark modemainHEAD

A light beam sweeps down the parent pointers, printing each commit

Watch it — press play

A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.

1 / 2

Step 1

Ask who did what

git log starts at HEAD and follows every parent pointer, printing each commit.

git log --oneline --graph
9a2f1c0init project4b7c2a5add componentsc86d9eestyle layout74d3b9ffeat: dark modemainHEAD

The newest commit is on top

Under the hood

1

It's a linked-list traversal

Commits only know their parents. Log starts at a ref (say HEAD), prints it, jumps to parent, prints it, and continues. Merchant/rendering aside, that IS the algorithm.

HEAD → 74d3b9f → parent → 4b7c2a5 → parent → 9a2f1c0 → <no parent>
2

--oneline formats one commit as one hash + subject

The short 7-character hashes come straight from the first 7 hex digits of the full 40-digit object hash. Two commits could theoretically collide in 7 digits — Git shows the abbreviated prefix only.

3

--graph draws the DAG

Merges make the commit list a graph, not a line. --graph tracks which 'lane' each commit belongs to and draws the branch topology with ASCII (or, with --color, painted) box-drawing characters.

4

Range and filter syntax

`git log main..feature` means 'commits reachable from feature but not from main' — read it as a set-difference over the DAG. `git log -p` appends the full diff of each commit.

Aliases the pros type

Memorize the git log concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:

git config --global alias.st # → git log --oneline --graph
AliasWhy people use it
g lg

The one-liner history view everyone pastes into their config.

g lgg

Every branch, fully drawn, with ref names.

g lgp

Compact log with per-commit file stats.

g ls

Deep dive: what each commit did to each file.

Command anatomy

git log [<revision range>]
--oneline

Each commit on one line: 7-char hash + subject.

--graph

Paint the branch topology with ASCII lanes.

-p

Show the full diff of every listed commit.

-n <count>

Limit output to the newest n commits.

--author=

Filter commits by author pattern.

-S"string"

Only commits where that string was added or removed.

When to reach for it

Answering 'what changed and when' — the daily archaeology of git.

Reviewing your own work before opening a PR: git log --oneline -10.

Finding when a bug appeared: git log -S"buggyExpr" -- file.

Pro tip

Add a lazy alias you'll use forever: `git config --global alias.tree "log --graph --oneline --all --decorate"`. Then `git tree` gives you the whole universe in one screen.

Go deeper with