Skip to content
Latchkey

git log Command: Inspect History in CI

git log prints the commit history reachable from a starting point, in configurable detail.

CI uses git log to build changelogs, capture the latest commit message, or list commits in a release range. The format flags make its output script-friendly.

Common flags

  • --oneline - one compact line per commit (short SHA plus subject)
  • -n N / -<N> - limit output to the most recent N commits
  • --format=<fmt> / --pretty=format:<fmt> - custom output with placeholders like %H, %s, %an
  • --since / --until - filter by date range
  • <from>..<to> - show commits in a range (e.g. last tag to HEAD)
  • --no-merges - exclude merge commits

Example

shell
# Generate a changelog since the previous tag
PREV="$(git describe --tags --abbrev=0 HEAD^)"
git log --no-merges --format="- %s (%h)" "${PREV}..HEAD"

In CI

Use --format with explicit placeholders so the output stays stable for parsing across Git versions. A range like PREV..HEAD is the standard way to scope a changelog to a single release. Remember log needs real history, so shallow clones may need a deeper fetch.

Key takeaways

  • git log --format gives deterministic, parseable output for changelog automation.
  • A from..to range scopes history to exactly one release.
  • Changelog steps usually need full history, so deepen shallow clones first.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →