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
bashgit log --onelineVisual branch graph
bashgit log --oneline --graph --all --decorateShows all branches and merge points as ASCII art.
Filter by author and date
bashgit log --author="Alice" --since="2 weeks ago" --onelineShow commits that changed a specific file
bashgit log --oneline -- src/auth/login.tsShow the diff introduced by each commit
bashgit 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`.