Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

git show command

git show command

Git Basic OperationsGit Basic Operations


git show The command is used to display detailed information about Git objects.

git show The command is used to view the content 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 [] []



  • : Specify the Git object to display. It can be a commit hash, tag, branch name, etc.
  • : options or format settings for display.
  • Common options and usage:

    Option Description Usage Examples
    --pretty=format: Customize the output format. Use a format string to display commit information. git show --pretty=format:"%h %s"
    --name-only Only display the names of changed files. git show --name-only
    --name-status Display the names of changed files and their change status (added, modified, deleted). git show --name-status
    --stat Display commit statistics, including changed files, line counts, and file changes. git show --stat
    --patch Display the diff patch of the commit (default behavior). git show --patch
    --color Display colored output for improved readability. git show --color
    --no-patch Do not show the patch; only show the commit information. git show --no-patch
    --abbrev-commit Display the shortened commit hash. git show --abbrev-commit
    --pretty=oneline Display commit information in a one-line format. git show --pretty=oneline

    Common usage

    1. Display detailed information about a commit

    Display detailed information about a commit, including the commit message, author, date, and changed files:

    
    
    git show 
    
    

    Example:

    
    
    git show 9a0d7b6
    
    

    2. Display the commit's differences

    Only display the differences (patch) contained in the commit:

    
    
    git show --patch 
    
    

    Example:

    
    
    git show --patch 9a0d7b6
    
    

    3. Display the commit's file list

    Only display the names of files changed in the commit:

    
    
    git show --name-only 
    
    

    Example:

    
    
    git show --name-only 9a0d7b6
    
    

    4. Display commit statistics

    Display commit statistics, including changed files and line counts:

    
    
    git show --stat 
    
    

    Example:

    
    
    git show --stat 9a0d7b6
    
    

    5. Display commit information using a custom format

    Use --pretty=format: to customize the output format of commit information:

    
    
    git show --pretty=format:"%h - %an, %ar : %s" 
    
    

    Example:

    
    
    git show --pretty=format:"%h - %an, %ar : %s" 9a0d7b6
    
    

    6. Display detailed information about a tag

    git show can also be used to view detailed information about a tag:

    
    
    git show 
    
    

    Example:

    
    
    git show v1.0
    
    

    Git Basic OperationsGit Basic Operations