git log
git
Usage
git log [--oneline] [--graph] [<range>] [-- <path>]Lists commit history newest first, but only the ancestors of the current HEAD — other branches need --all.
Common flags
| Flag | Meaning |
|---|---|
| --oneline | one short line per commit |
| --graph | draw the branch lines |
| --all | include every branch, not just the current one |
| -p | show the patch of each commit |
| --stat | show which files changed |
| -n <n> | stop after n commits |
| --since=<date> | commits newer than a date, e.g. "2 weeks ago" |
| --follow | keep following one file through renames |
Examples
git log --oneline --graph --allthe whole history as a compact graph
git log -p -- src/app.tsevery change ever made to one file
git log --since="2 weeks ago" --author=jaderecent commits by one person
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git log do?
Lists commit history newest first, but only the ancestors of the current HEAD — other branches need --all.
Q. How do I type it?
git log [--oneline] [--graph] [<range>] [-- <path>] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
8 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-log