Skip to content
LatchkeyLatchkey home

git show Command: Inspect Objects in CI

git show prints the details of a Git object: a commit and its diff, a tag, or a file at a revision.

CI uses git show to extract a commit message for a release note or to read a file as it existed at another ref without checking it out.

Common flags

  • <commit> - show a commit message and its diff
  • -s / --no-patch - suppress the diff and show only the message
  • --format=<fmt> / --pretty=<fmt> - control the output format
  • <rev>:<path> - print the contents of a file as of a revision
  • --stat - summarize changed files instead of the full patch
  • --name-only - list only the files a commit touched

Example

shell
# Grab the subject line of the triggering commit
SUBJECT="$(git show -s --format=%s HEAD)"
# Read a config file as it was on main, without checkout
git show origin/main:config/app.yaml

In CI

git show -s --format=%s HEAD is the compact way to pull a commit subject for notifications. The <rev>:<path> form lets a step compare or read a file from another branch without switching the working tree.

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

Key takeaways

  • git show -s --format=%s extracts just a commit message for release notes or alerts.
  • The <rev>:<path> syntax reads a file from any ref without a checkout.
  • Add --stat or --name-only when you only need the list of touched files.

Frequently asked questions

git show Command: Inspect Objects in CI?
CI uses git show to extract a commit message for a release note or to read a file as it existed at another ref without checking it out.
In CI?
git show -s --format=%s HEAD is the compact way to pull a commit subject for notifications. The <rev>:<path> form lets a step compare or read a file from another branch without switching the working tree.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card