How do you view commit history in Git?

Use git log with various flags to browse, filter, and format your repository's commit history.

GitVersion Control

Overview

`git log` is your window into a repository's history. With the right flags it becomes a powerful tool for investigating changes, tracing bugs, and understanding who changed what and when.

Key Points

  • •`git log --oneline` gives a compact one-line-per-commit view great for a quick overview.
  • •`--graph --all` visualises branch and merge structure in the terminal.
  • •`--author`, `--since`, `--until`, and `--grep` filter commits by author, date, or message.
  • •`git log -p` shows the full diff for each commit.
  • •`git log -- <file>` shows only commits that touched a specific file.

Examples

Compact one-line log

bash
git log --oneline

Visual branch graph

bash
git log --oneline --graph --all --decorate

Shows all branches and merge points as ASCII art.

Filter by author and date

bash
git log --author="Alice" --since="2 weeks ago" --oneline

Show commits that changed a specific file

bash
git log --oneline -- src/auth/login.ts

Show the diff introduced by each commit

bash
git log -p --follow -- src/utils/format.ts

--follow traces renames across commits.

Pro Tip

Add a global alias for a pretty log format once and use it forever: `git config --global alias.lg "log --oneline --graph --all --decorate"` Then just type `git lg`.