Home·Terminal commands

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

FlagMeaning
--onelineone short line per commit
--graphdraw the branch lines
--allinclude every branch, not just the current one
-pshow the patch of each commit
--statshow which files changed
-n <n>stop after n commits
--since=<date>commits newer than a date, e.g. "2 weeks ago"
--followkeep following one file through renames

Examples

git log --oneline --graph --all

the whole history as a compact graph

git log -p -- src/app.ts

every change ever made to one file

git log --since="2 weeks ago" --author=jade

recent 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