git log walks the commit history from a starting point, formatted however you need.
Log is the workhorse for inspecting history and generating changelogs. Custom --pretty formats keep output stable for scripts.
What it does
git log lists commits reachable from a given ref (HEAD by default), in reverse-chronological order, with configurable formatting and filtering.
Common usage
Terminal
git log --oneline --graph --decorate
git log -n 5
git log --pretty=format:"%h %s (%an)"
git log main..feature # commits in feature not in main
git log --since="2 weeks ago" -- path/
Options
Flag
What it does
--oneline
One compact line per commit
--graph
ASCII branch/merge graph
--pretty=format:<fmt>
Custom, stable output format
-n <count> / -<count>
Limit number of commits
--since / --until / --author
Filter by date or author
Common errors in CI
fatal: your current branch 'main' does not have any commits yet - a fresh repo. With a shallow clone, log shows only the fetched commits, so a range like main..feature can look empty or wrong; deepen with git fetch --unshallow or fetch-depth: 0.
Using this in CI
CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.
.github/workflows/ci.yml
- uses:actions/checkout@v4with:fetch-depth:0 # history, tags, and git describe all need this- run:|git rev-parse --is-shallow-repository # expect falsegit rev-parse --abbrev-ref HEAD # prints HEAD when detached
Frequently asked questions
git log: Usage, Options & Common CI Errors?
Log is the workhorse for inspecting history and generating changelogs. Custom --pretty formats keep output stable for scripts.
What it does?
git log lists commits reachable from a given ref (HEAD by default), in reverse-chronological order, with configurable formatting and filtering.
Common errors in CI?
fatal: your current branch 'main' does not have any commits yet - a fresh repo. With a shallow clone, log shows only the fetched commits, so a range like main..feature can look empty or wrong; deepen with git fetch --unshallow or fetch-depth: 0.