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
| 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.
Related guides
git shortlog: Usage, Options & Common CI Errorsgit shortlog summarizes commits grouped by author, perfect for changelogs and release notes. Reference for -s…
git show: Usage, Options & Common CI Errorsgit show displays a commit, tag, or object with its diff. Reference for --stat, --name-only, blob viewing, an…
git diff: Usage, Options & Common CI Errorsgit diff shows changes between commits, the index, and the working tree. Reference for --staged, --name-only,…
git reflog: Usage, Options & Common CI Errorsgit reflog records where HEAD and branches have been, so you can recover lost commits. Reference for show, ex…