The git show
is a command to view objects such as blobs, trees, commits, and tags. Primarily, git show
is used to display the commit message and the differences introduced by a commit. This includes information about the author, the date, and the actual changes made to the files.
Basic Syntax and Usage
The basic syntax of git show
is straightforward and allows you to specify the Git object you want to inspect. The general structure of the command is:
git show <object>
Here, <object>
can be a commit hash, tag name, or other Git object identifiers. Below are some common usages:
To view the most recent commit, you can use the HEAD
reference:
git show HEAD
This command displays the latest commit's message, author, date, and the diff of changes introduced by this commit.
To view details of a specific commit, you use the commit hash:
git show <commit-hash>
You can get commit hash using git log --oneline
.
For example, if the commit hash is 1a2b3c4d
, the command would be:
git show 1a2b3c4d
To view details of a tag, including the associated commit
git show <tag-name>
For example, to view the tag v1.0
git show v1.0
git show examples
1. Viewing Commit Detail
List the objects.
git cat-file --batch-check --batch-all-objects
And check the details of the latest commit, blob, tag and tree.
git show 02bed804eaf26951a769491df9227e6756727aa9 git show 28fab796c76056ab246eaa479428c8aedcc9e836 git show 31a202f5ee4fa45a4487010e5cd509d2fe6ee925
2. Viewing Tag Information
To view the details of a tag, you use the git show
command followed by the tag name. This will display the tag's metadata, the tag message (if any), and the details of the commit the tag points to.
git show v1.3
When you run this command, Git will show information about the tag v1.0
, including:
- Tagger: The person who created the tag.
- Tag date: When the tag was created.
- Tag message: The message associated with the tag.
- Commit details: The details of the commit the tag points to, including the commit message, author, date, and the diff of changes introduced by the commit.
3. Customizing Output with Pretty Formats
You can git-show a commit object's output by controlling portions to view. For instance, the oneline
decoration
git show --pretty=oneline
shows only the diffs data, ignoring the author and timestamp information. The full
option
git show --pretty=full
shows the author information, commit message, and diffs of the latest commit.
We can also use the --abbrev-commit
options to control git-show latest commit SHA1 output characters. The --abbrev-commit
reveals seven characters
git show --abbrev-commit
Whereas the --no-abbrev-commit
option shows the forty characters.
git show --no-abbrev-commit
Similar to full
but includes more detailed information about the author and committer dates.
git show --pretty=fuller
Formats the output similar to an email message, useful for patch emails.
git show --pretty=email
To check the raw format of the changes, which includes the commit info and the file mode changes.
git show --raw
To display the full diff of changes introduced by the commit (default when no specific diff format is provided).
git show --patch
To provide a summary of changes with statistics about the number of insertions and deletions for each file.
git show --stat
Key Takeaway
The git-show command is crucial in exploring the contents of a git object. However, failure to understand git objects can prevent you from exploiting the full potential of the command.
Now that you have a deep understanding of git and git objects, go ahead and manipulate the objects using plumbing and porcelain git commands, as illustrated in this tutorial.