Git Show

Updated · 10 min read
easyGit 2.53gitgit-showhistoryinterview

A library catalog tells you which books exist. To read one, you take it off the shelf and open it.

git log is the catalog of your commits. git show takes one commit off the shelf and opens it: who made it, when, why, and exactly which lines it changed. It can also show you a single file as it was in that commit, which is the quickest way to answer "what did this file say last week?"

In this lesson, you will learn to show a commit in full or in short, and to read any file from any commit without changing your working tree.

The Starting Point

Navika's project has four commits. The last one, from Advitha, changed two files:

Terminal
mkdir fee-tracker
cd fee-tracker
git init --quiet
echo "Fee Tracker" > README.md
git add README.md
git commit --quiet -m "Add project README"
printf 'Term 1 fee: $12,000\nTerm 2 fee: $12,000\n' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fees"
printf 'Term 1 fee: $12,000\nTerm 2 fee: $12,500\n' > fees.txt
git commit --quiet -a --author="Srihitha Anamaneni <srihitha@example.com>" -m "Fix the term 2 fee" -m "The office raised it in December."
echo "class FeeCalculator {}" > FeeCalculator.java
echo 'Late fee: $250' >> fees.txt
git add FeeCalculator.java
git commit --quiet -a --author="Advitha Anamaneni <advitha@example.com>" -m "Add the late fee rule"
git log --oneline
Output
95d07b6 (HEAD -> main) Add the late fee rule
9e1fcfc Fix the term 2 fee
fe87780 Add the term fees
dd34d8a Add project README

Show the Newest Commit

With nothing after it, git show shows the commit you are on, HEAD:

Terminal
git show
Output
commit 95d07b663600db4f9f549215ebbf19dcca5b80fb (HEAD -> main)
Author: Advitha Anamaneni <advitha@example.com>
Date:   Mon Jan 5 10:15:00 2026 -0600
 
    Add the late fee rule
 
diff --git a/FeeCalculator.java b/FeeCalculator.java
new file mode 100644
index 0000000..2bec87b
--- /dev/null
+++ b/FeeCalculator.java
@@ -0,0 +1 @@
+class FeeCalculator {}
diff --git a/fees.txt b/fees.txt
index 6da94ac..cd71fba 100644
--- a/fees.txt
+++ b/fees.txt
@@ -1,2 +1,3 @@
 Term 1 fee: $12,000
 Term 2 fee: $12,500
+Late fee: $250

How it works

  1. The top part is the same as in git log: the commit ID, the author, the date and the message.
  2. Then comes one diff for each changed file. FeeCalculator.java is a new file (new file mode, and --- /dev/null, meaning "nothing before"), so all its lines start with +.
  3. In fees.txt, one line was added at the end. The lines without a sign are unchanged context.

The lesson "How to Read a Diff" goes through every line of this format.

Show Any Commit

To open an older commit, give its ID. The short ID from git log --oneline is enough:

Terminal
git show 9e1fcfc
Output
commit 9e1fcfcc35c251564275435cf6e7d35ebb364c8e
Author: Srihitha Anamaneni <srihitha@example.com>
Date:   Mon Jan 5 10:11:00 2026 -0600
 
    Fix the term 2 fee
 
    The office raised it in December.
 
diff --git a/fees.txt b/fees.txt
index c531a66..6da94ac 100644
--- a/fees.txt
+++ b/fees.txt
@@ -1,2 +1,2 @@
 Term 1 fee: $12,000
-Term 2 fee: $12,000
+Term 2 fee: $12,500

This is Srihitha's fix. The - line is the old value and the + line is the new one. Because the message has a body, it is shown in full too.

Syntax

Terminal
git show [options] [<commit>]
git show <commit>:<path>
Option or formIt is used to
git showShow the newest commit (HEAD)
git show <commit>Show one commit: details and changes
--statShow the changed files with counts, instead of the full changes
--name-onlyShow only the names of the changed files
--name-statusShow the names with a letter: A added, M modified, D deleted, R renamed
-sShow the details only, without any changes
--onelineShow the details as one line
git show <commit>:<path>Print a file exactly as it was in that commit

Just the Summary

A commit that changed fifty files is too long to read in full. These options show less:

Terminal
git show --stat
Output
commit 95d07b663600db4f9f549215ebbf19dcca5b80fb (HEAD -> main)
Author: Advitha Anamaneni <advitha@example.com>
Date:   Mon Jan 5 10:15:00 2026 -0600
 
    Add the late fee rule
 
 FeeCalculator.java | 1 +
 fees.txt           | 1 +
 2 files changed, 2 insertions(+)
Terminal
git show --name-status --oneline
Output
95d07b6 (HEAD -> main) Add the late fee rule
A	FeeCalculator.java
M	fees.txt

--name-status gives one line per file with a letter: A for a file that was added and M for one that was modified. Combined with --oneline, it is a compact answer to "what did this commit touch?".

To see only the details, with no changes at all, use -s:

Terminal
git show -s 9e1fcfc
Output
commit 9e1fcfcc35c251564275435cf6e7d35ebb364c8e
Author: Srihitha Anamaneni <srihitha@example.com>
Date:   Mon Jan 5 10:11:00 2026 -0600
 
    Fix the term 2 fee
 
    The office raised it in December.

A File as It Was in an Older Commit

This is the form of git show that people forget, and then need every week. Put a colon and a path after the commit, and Git prints that file as it was in that commit:

Terminal
git show fe87780:fees.txt
Output
Term 1 fee: $12,000
Term 2 fee: $12,000

That is fees.txt from "Add the term fees", before Srihitha's fix and before the late fee. Your working tree is not touched: the file in your folder still has three lines. The path is always written from the top folder of the repository, such as docs/guide.md.

To keep an old version as a separate file, send the output to a file:

Terminal
git show fe87780:fees.txt > fees-old.txt
cat fees-old.txt
Output
Term 1 fee: $12,000
Term 2 fee: $12,000
What git show prints for each kind of name

Naming a Commit Without Its ID

You don't always have to copy an ID. HEAD is the newest commit, and HEAD~1 is the one before it:

Terminal
git show --oneline -s HEAD~1
Output
9e1fcfc Fix the term 2 fee

HEAD~2 is two commits back, and so on. The lesson "Naming Commits: HEAD, ~ and ^" covers every way to name a commit.

Common Mistakes

Using a space instead of a colon. git show fe87780 fees.txt shows the commit's changes to fees.txt. git show fe87780:fees.txt prints the file's content. Both are useful, but they are different.

Giving a path relative to the current folder. In <commit>:<path>, the path starts at the top of the repository. Inside docs/, write git show HEAD:docs/guide.md, or git show HEAD:./guide.md to mean "relative to here".

Asking for a file from a commit that didn't have it. git show fe87780:FeeCalculator.java fails, because that file was added in a later commit. Git says the path does not exist in that commit.

Reading a huge commit in full. Start with --stat or --name-status, then show one file's changes with git show <commit> -- <path>.

Thinking git show restores a file. It only prints. Use git restore --source to bring an old version back.

Under the Hood

git show works on any Git object, not only commits, and shows each in a suitable way. For a commit, it prints the details and the diff against its parent. With <commit>:<path>, it finds the blob (the stored file content) for that path in the commit's snapshot and prints it as it is. Give it a folder, and it lists the folder's content as it was in that commit:

Terminal
git show HEAD:
Output
tree HEAD:
 
FeeCalculator.java
README.md
fees.txt

The empty path after the colon means the top folder. The first line, tree HEAD:, says that the object is a tree (a folder), and the lines after it are its entries. This is the commit's tree, the snapshot you met in "Inside the .git Folder", shown in a readable form.

Interview Corner

What is the difference between git log and git show?

git log lists many commits, newest first, and by default shows only their details. git show shows one object, by default the latest commit, with its details and its changes. git log -p -1 is roughly the same as git show.

How do you see the contents of a file as it was in an earlier commit?

git show <commit>:<path>, with the path from the top of the repository. It prints the file without changing the working tree. Redirect the output to save it, or use git restore --source=<commit> <path> to replace the current file.

How do you list only the files a commit changed?

git show --name-only <commit> for the names, or --name-status for the names with A, M, D or R. --stat adds the number of lines changed.

What does git show show for a merge commit?

By default, a combined diff that shows only the parts that differ from all parents, which is often nearly empty. Use git show --first-parent <merge> or git diff <merge>^1 <merge> to see what the merge brought in. Merges are covered in a later lesson.

Practice

Challenge: compare two versions. In the same repository, print fees.txt as it was in Srihitha's commit (9e1fcfc), and then the names and status letters of the files changed by the newest commit, on one line of details.

What does Git print? Before you open the solution, write down how many lines the old fees.txt has, and which letter each file of the newest commit gets.

Show solution
Terminal
git show 9e1fcfc:fees.txt
git show --name-status --oneline HEAD
Output
Term 1 fee: $12,000
Term 2 fee: $12,500
95d07b6 (HEAD -> main) Add the late fee rule
A	FeeCalculator.java
M	fees.txt

Srihitha's version has two lines: her corrected term 2 fee, and no late fee yet. The newest commit added FeeCalculator.java (A) and modified fees.txt (M).

Checkpoint. In a project of your own, pick a file that has changed several times. Use git log --oneline -- <file> to find three of its commits, and git show <commit>:<file> to read each version. Write down one sentence about what changed between them.

Quick check: Git show

4 questions
1What does git show with no arguments show?
2Which command prints fees.txt as it was in commit fe87780?
3In git show --name-status, what does A mean?
4Does git show <commit>:<file> change the file in your folder?

Key Takeaways

Quick reference

CommandIt is used to
git showShow the newest commit
git show <commit>Show one commit with its changes
git show --stat <commit>Show the files a commit changed, with counts
git show --name-status <commit>Show changed files with A, M, D, R
git show -s <commit>Show the details without the changes
git show <commit> -- <path>Show only one file's changes in a commit
git show <commit>:<path>Print a file as it was in a commit
git show HEAD:List the top folder as it is in the newest commit

Was this tutorial helpful?

Lesson 18 of 106