# git log: Usage, Options & Common CI Errors

> git log shows commit history with flexible formatting. Reference for --oneline, --graph, --pretty, ranges, and the empty-log shallow-clone surprise in CI.

Source: https://latchkey.dev/learn/command-reference/git-log  
Updated: 2026-06-25

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@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
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
