Open book with Git branch and cloud

Git Show

What is git-show?

git-show is a command line utility that is used to view expanded details on Git objects such as blobs, trees, tags, and commits. git-show has specific behavior per object type.

Tags show the tag message and other objects included in the tag. Trees show the names and content of objects in a tree. Blobs show the direct content of the blob. Commits show a commit log message and a diff output of the changes in the commit.

Git objects are all accessed by references. By default, git-show acts against the HEAD reference. The HEAD reference always points to the last commit of the current branch. Therefore, you can use git-show to display the log message and diff output of the latest commit.

Git-show options

<object>…‚Äč
A reference to an object or a list of objects may be passed to examine those specific objects. If no explicit objects are passed, git-show defaults to the HEAD reference.

--pretty[=<format>]
The pretty option takes a secondary format value that can be one of: oneline, short, medium, full, fuller, email, raw, and format:<string>. If omitted, the format defaults to medium. Each format option is a different template for how Git formats the show output. The <code>oneline</code> option can be very helpful for showing a list of commits

--abbrev-commit
This option shortens the length of output commit IDs. Commit IDs are 40 characters long and can be hard to view on narrow terminal screens. This option combined with --pretty=oneline can produce a highly succinct git log output.

--no-abbrev-commit
Always Show the full 40 character commit ID. This will ignore --abbrev-commit and any other options that abbreviate commit IDs like the --oneline format

--oneline
This is a shortcut for using the expanded command --pretty=oneline --abbrev-commit

--encoding[=<encoding>]
Character encoding on Git log messages defaults to UTF-8. The encoding option can change to a different character encoding output. This is useful if you are working with Git in an environment with different character encoding, like an Asian language terminal.

>--expand-tabs=<n>
--expand-tabs
--no-expand-tabs

These options replace tab characters with spaces in the log message output. The n value can be set to configure how many space characters the tabs expand to. Without an explicit n value tabs will expand to 8 spaces. --no-expand-tabs is equivalent to n=0

--notes=<ref>
--no-notes

Git has a note system that enables arbitrary ‘note’ metadata to be attached to objects. This data can be hidden or filtered when using git-show

--show-signature
This option will validate the commit is signed with an encrypted signature by passing it to a gpg subcommand.

Pretty formats for git-show

The --pretty option discussed above accepts several secondary options to massage the format of git-show output. These secondary options are listed below with example template

  • oneline
    <sha1> <title line>

Oneline attempts to compact as much info into a single line as possible

  • short
    commit <sha1>
    Author: <author>
    <title line>
  • medium
    commit <sha1>
    Author: <author>
    Date: <author date>
    <title line>
    <full commit message>
  • full
    commit <sha1>
    Author: <author>
    Commit: <committer>
    <title line>
    <full commit message>
  • fuller
    commit <sha1>
    Author: <author>
    AuthorDate: <author date>
    Commit: <committer>
    CommitDate: <committer date>
    <title line>
    <full commit message>
  • email
    From <sha1> <date>
    From: <author>
    Date: <author date>
    Subject: [PATCH] <title line>
    <full commit message>
  • raw
    raw format ignores other direct formatting options passed to git-show and outputs the commit exactly as stored in the object. Raw will disregard --abrev and --no-abbrev and always show the parent commits.
  • format:
    format enables the specification of a custom output format. It works similar to the C language’s printf command. The --pretty=format option takes a secondary value of a template string. The template has access to placeholder variables that will be filled with data from the commit object. These placeholders are listed below:

    %H: commit hash
    %h: abbreviated commit hash
    %T: tree hash
    %t: abbreviated tree hash
    %P: parent hashes
    %p: abbreviated parent hashes
    %an: author name
    %aN: author name 
    %ae: author email
    %aE: author email 
    %ad: author date (format respects --date= option)
    %aD: author date, RFC2822 style
    %ar: author date, relative
    %at: author date, UNIX timestamp
    %ai: author date, ISO 8601 format
    • %cn: committer name
    %cN: committer name 
    %ce: committer email
    %cE: committer email 
    %cd: committer date
    %cD: committer date, RFC2822 style
    %cr: committer date, relative
    %ct: committer date, UNIX timestamp
    %ci: committer date, ISO 8601 format
    %d: ref names, like the --decorate option of git-log(1)
    %e: encoding
    %s: subject
    %f: sanitized subject line, suitable for a filename
    • %b: body
    %N: commit notes
    %gD: reflog selector, e.g., refs/stash@{1}
    %gd: shortened reflog selector, e.g., stash@{1}
    %gs: reflog subject
    %Cred: switch color to red
    %Cgreen: switch color to green
    %Cblue: switch color to blue
    %Creset: reset color
    %C(...): color specification, as described in color.branch.* config option
    %m: left, right or boundary mark
    %n: newline
    %%: a raw %
    %x00: print a byte from a hex code
    %w([<w>[,<i1>[,<i2>]]]): switch line wrapping, like the -w option of git-shortlog

Examples of git-show

git show --pretty="" --name-only bd61ad98

This will list all the files that were touched in a commit

git show REVISION:path/to/file

This will show a specific version of a file. Replace the REVISON with a Git sha.

git show v2.0.0 6ef002d74cbbc099e1063728cab14ef1fc49c783

This will show the v2.0.0 tag and also commit at 6ef002d74cbbc099e1063728cab14ef1fc49c783

git show commitA...commitD

This will output all commits in the range from commitA to commit D

Summary

git-show is a very versatile command for examining objects in a Git repo. It can be used to target specific files at specific revisions. Examining a commit range with git-show will output all the individual commits between the range. git-show can be a helpful tool for creating patch notes and tracking changes in a repository.