Sub topic 3
Making log readable: --oneline, --graph, --decorate, --pretty
The default git log prints several lines per commit. That is too much to scan in a large repository. This chapter covers the options that make the output compact and show how commits relate to each other.
This chapter assumes you can run basic Git commands and know that each commit points to its parent commit or commits. It builds on the default git log output from the previous chapter.
Compact output with --oneline
--oneline prints one line per commit: an abbreviated hash followed by the subject line of the message.
git log --onelineIt is shorthand for --pretty=oneline --abbrev-commit. You get a short hash that is usually 7 characters, and the rest of the message is left out.
Drawing the graph with --graph
--graph draws ASCII lines in the left margin. They show branches splitting and merging.
git log --oneline --graphEach * marks a commit. The |, / and \ characters show how lines of history join. Without --graph, a merge looks like any other commit, and you cannot tell which branch a commit came from.
Labeling commits with --decorate
--decorate adds the names of branches and tags beside the commits they point to. Recent Git versions turn it on automatically when output goes to a terminal. Passing it explicitly makes the result the same in scripts and pipes.
git log --oneline --graph --decorate -n 10The decoration looks like (HEAD -> main, origin/main, tag: v1.2). HEAD -> main means you have main checked out. origin/main is a remote-tracking branch. This command shows the ten most recent commits.
Each arrow points from a parent to a child here. Git itself stores the reverse: each commit records its parents.
Custom formats with --pretty
--pretty selects a built-in format or builds your own. The built-in formats are oneline, short, medium (the default), full, fuller and reference.
For a custom layout, use --pretty=format: followed by placeholders.
git log --pretty=format:"%h %an %ad %s" --date=shortThis prints the abbreviated hash, author name, short date and subject:
| Placeholder | Meaning |
|---|---|
| `%H` | Full commit hash |
| `%h` | Abbreviated commit hash |
| `%an` | Author name |
| `%ae` | Author email |
| `%ad` | Author date, styled by `--date` |
| `%ar` | Author date, relative ("3 days ago") |
| `%s` | Subject line |
| `%d` | Branch and tag decorations |
--date=short gives 2026-12-04. Other useful values are iso, relative and format: with a strftime pattern.
You can add colors with %C placeholders, which lets you mix a custom format with the graph:
git log --graph --pretty=format:"%C(yellow)%h%C(reset) %C(green)%ad%C(reset) %s%C(auto)%d" --date=short%C(auto) colors the decoration the way Git normally would.
Common errors
format:versustformat:. Withformat:, Git puts a newline between commits but not after the last one.--pretty=tformat:ends every entry with a newline. A plain--pretty="..."with a%placeholder behaves liketformat:.- Forgetting that
--onelinereplaces your format. If you pass both--onelineand--pretty=format:..., the option that comes last wins. - Reading
--graphoutput in a different order.--graphforces commits to appear in a layout that keeps lines readable. Parents always appear after their children, but the order may differ from plain date order.
Exercise
You run git log --pretty=format:"%h %s" and the shell prompt appears on the same line as the last commit. Which option fixes this, and why?
Show answer
Use --pretty=tformat:"%h %s". The format: style adds a newline only between commits, so the last line has none. tformat: ends every entry with a newline.
Exercise
Write a command that shows all branches as a graph, one line per commit, with branch and tag names.
Show answer
git log --oneline --graph --decorate --all. The --all option starts the walk from every branch and tag instead of only from HEAD.