Skip to content
LatchkeyLatchkey home

git log: Usage, Options & Common CI Errors

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

FlagWhat it does
--onelineOne compact line per commit
--graphASCII branch/merge graph
--pretty=format:<fmt>Custom, stable output format
-n <count> / -<count>Limit number of commits
--since / --until / --authorFilter 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@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git 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.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card