CodeBlanks Logo Icon CodeBlanks

git show

Learn to view a commit's content with git show.

Inspect commits with git show

The git show command gives detailed information about a specific commit. It prints the commit message, author, date, and the diff of changes introduced by that commit. If you don't supply a parameter, it displays the latest commit (HEAD) by default.

git show
git show a1b2c3d

This command is used to understand exactly which lines were added or removed in the past.

git show options

By adding the -s flag to git show, you can hide the patch diff and view only the commit summary. If you want to list only the changed files, use the --name-only option. You can also directly view the content of a file at a specific commit.

git show -s HEAD
git show --name-only HEAD
git show HEAD:notlar.txt

This allows you to inspect the exact state of a file at that commit without touching your working directory.

Practice Read a file as of a commit

Use git show to print the content of the notlar.txt file directly from the HEAD commit.

Starter code

terminal
git init -q
git config user.name "Ahmet"
git config user.email "ahmet@example.com"
echo "CodeBlanks Git Dersleri" > notlar.txt
git add notlar.txt
git commit -qm "Notlar dosyasi eklendi"

# Dosyanin son commit icerigini ekrana yazdir

Sample solution

terminal
git init -q
git config user.name "Ahmet"
git config user.email "ahmet@example.com"
echo "CodeBlanks Git Dersleri" > notlar.txt
git add notlar.txt
git commit -qm "Notlar dosyasi eklendi"

git show HEAD:notlar.txt

Expected output

CodeBlanks Git Dersleri

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does the git show command display when run without any parameters?

  • The contents of the very first commit in the repository
  • The details and diff of the HEAD commit Correct answer
  • A one-line list of all commits in the repository
  • Only the file diffs that are not yet staged

Explanation: git show defaults to presenting the information and diff output of the latest commit pointed to by HEAD.

2 Hide commit patch

Question
git show ____ HEAD
Answer
git show -s HEAD

Explanation: The -s option suppresses the diff patch and only displays commit metadata.

3 git show commands

Term Meaning
git show Latest commit detail and diff
git show <hash> Content of specified commit
git show -s Commit info without diff
git show --name-only Only changed file names

All lessons in Beginner