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