git log
Beginner Git CLI Safe
Summary: git log walks the chain of commits backwards from HEAD (or from any branch, tag or hash you name) and prints them. Every flag either changes the format or filters the list.
Safe — it only reads. Run it as often as you like.
What it does
Starts at a commit, prints it, follows its parent, and repeats. The default format shows the full hash, author, date and message; options shorten it, draw the branch graph, add labels, add file statistics, or restrict which commits appear.
Why it exists
History is only useful if you can read it. git log is the reader; everything else (show, blame, diff) drills into what it lists.
When to use it
- Before pushing: what am I about to send? (
git log --oneline origin/main..HEAD) - Finding when and why something changed (
--oneline -- <file>,-S "<text>",--grep). - Understanding the branch situation (
--oneline --graph --decorate --all). - Writing release notes (
--oneline v1.2.0..main).
When not to use it
- To see uncommitted work (that is
git statusandgit diff). - To look inside one commit in detail (that is
git show).
Syntax
| Form | Meaning |
|---|---|
git log |
Full format, newest first, current branch |
git log --oneline |
One line per commit: short hash and subject |
git log --oneline --graph --decorate --all |
Branch graph with labels, all branches (the git lg alias) |
git log -n 5 or -5 |
Only the newest 5 |
git log --stat |
Add files changed per commit |
git log -p |
Add the full diff per commit |
git log -- <path> |
Only commits touching the path (--follow to trace renames) |
git log --author=<name> |
By author |
git log --since=<date> --until=<date> |
By date ("2026-09-03", "2 weeks ago") |
git log --grep=<text> |
Messages containing text |
git log -S "<text>" |
Commits whose diff adds or removes the text |
git log <a>..<b> |
Commits in b that are not in a |
git log --pretty=format:"%h %ad %an %s" --date=short |
Custom line format |
Examples
$ git log --oneline -5c541c80 docs: add maintainer note
79c86c5 feat: add Eagle Ridge trail (#21)
dcc61f1 docs: describe the region and answer a data question (#28)
8e4a443 chore: add todo
a32e63b docs: remove tmp$ git log --oneline --graph --decorate -4* c541c80 (HEAD -> main) docs: add maintainer note
* 79c86c5 feat: add Eagle Ridge trail (#21)
* dcc61f1 docs: describe the region and answer a data question (#28)
* 8e4a443 chore: add todo$ git log --oneline -- docs/faq.mddcc61f1 docs: describe the region and answer a data question (#28)
2f543f1 docs: explain how to add a trail (#27)
0d9eb38 docs: add map question to FAQ (#9)
8fa922e Initial import of trailguide$ git log --oneline --grep="#21"79c86c5 feat: add Eagle Ridge trail (#21)$ git log --pretty=format:"%h %ad %an %s" --date=short -3c541c80 2026-09-07 Ana docs: add maintainer note
79c86c5 2026-09-07 Ana feat: add Eagle Ridge trail (#21)
dcc61f1 2026-09-07 Ana docs: describe the region and answer a data question (#28)Full format for one commit:
$ git log -1commit 97773ae0017c4eb07f069e6008fba12c656e0a9a
Author: Ana <ana@northwind-trails.example>
Date: Thu Sep 3 14:30:00 2026 +0200
docs: add Windows steps to installation guide (#12)Expected result
Text only; nothing changes. Long output opens in the pager: Space forward, q quit, /text to search.
Common mistakes
- Stuck in the pager. Press q.
- A file name that matches a branch name. Put
--before the path. - Looking for uncommitted changes. They are not commits.
--sincewithout quotes for dates with spaces.- Expecting other branches' commits. By default only the current branch; add
--all.
How to undo or recover
Nothing to undo.
In VS Code
Source Control Graph in the Source Control view; Timeline for one file; GitLens for more. See Reading history.
In IntelliJ IDEA
Git → Log tab (Alt+9 / ⌘9) with branch, author, date and text filters; right-click a file → Git → Show History.
Related commands
git show opens one commit · git blame maps lines to commits · git diff compares two points the log names · git reflog lists where HEAD has been, including commits the log no longer shows.
Lessons that use this command
Reading history · Commits, hashes and history · HEAD, refs, origin · Lab 1.