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
git shortlog Command: Summarize Authors in CIgit shortlog groups commits by author. Reference for -s, -n, and ranges to build contributor summaries and re…
git describe Command: Version Strings in CIgit describe builds a human-readable version from tags. Reference for --tags and --always to derive build ver…
git rev-list Command: Count Commits in CIgit rev-list lists commit objects in reverse chronological order. Reference for --count to derive monotonic b…
git show Command: Inspect Objects in CIgit show displays commits, tags, and file contents at a revision. Reference for printing a commit message or…