git show command
git showThe command is used to display detailed information about Git objects.
git showThe command is used to view the contents of commits, tags, tree objects, or other Git objects. This command is very useful for reviewing commit history, viewing the specific content of commits, and debugging Git objects.
Basic Syntax
git show [<options>] [<object>]
<object>: Specifies the Git object to display. It can be a commit hash, tag, branch name, etc.<options>: Displayed options or format settings.
Common options and usage:
| Options | Description | UsageExample |
|---|---|---|
--pretty=format: | Customize the output format. Use format strings to display commit information. | git show --pretty=format:"%h %s" <commit-hash> |
--name-only | Only display changed file names. | git show --name-only <commit-hash> |
--name-status | Display the names of changed files and their change status (added, modified, deleted). | git show --name-status <commit-hash> |
--stat | Display commit statistics, including changed files, line count, and file changes. | git show --stat <commit-hash> |
--patch | Display the diff patch of the commit (default behavior). | git show --patch <commit-hash> |
--color | Display color output to improve readability. | git show --color <commit-hash> |
--no-patch | Do not display patches; only display commit information. | git show --no-patch <commit-hash> |
--abbrev-commit | Display abbreviated commit hash. | git show --abbrev-commit <commit-hash> |
--pretty=oneline | Display commit information in a single-line format. | git show --pretty=oneline <commit-hash> |
Common usage
1. Display detailed commit information.
Display detailed commit information, including commit message, author, date, and changed files:
git show <commit-hash>
Example:
git show 9a0d7b6
2. Display the commit diff.
Display only the diff (patch) contained in the commit:
git show --patch <commit-hash>
Example:
git show --patch 9a0d7b6
3. Display the list of files in the commit.
Only display the names of files changed in the commit:
git show --name-only <commit-hash>
Example:
git show --name-only 9a0d7b6
4. Display commit statistics.
Display commit statistics, including changed files and line count:
git show --stat <commit-hash>
Example:
git show --stat 9a0d7b6
5. Use a custom format to display commit information
Use --pretty=format: to customize the output format of commit information:
git show --pretty=format:"%h - %an, %ar : %s" <commit-hash>
Example:
git show --pretty=format:"%h - %an, %ar : %s" 9a0d7b6
6. Display detailed tag information.
git show can also be used to view detailed tag information:
git show <tag>
Example:
git show v1.0
other extensions