Course contentsShow
← Software Engineering
Lesson 120 of 1,9333. Collaboration with GitFree lesson

Git Show and Diff: Inspecting Changes

Examine specific commits and compare different versions of code using git show and git diff commands effectively.

Git Show and Diff: Inspecting Changes

You'll learn how to examine specific commits and compare different versions of your code using Git's inspection tools.

Why Inspect Changes?

When reviewing history or debugging issues, you need to see exactly what changed. While git log shows you commit messages and git blame shows who wrote each line, git show and git diff reveal the actual code changes themselves.

Git Show: Examining a Specific Commit

The git show command displays everything about a particular commit: the author, date, message, and the full diff of changes made.

git show abc123

This shows you what happened in commit abc123. Think of it as opening a sealed envelope from your project's past—you see the message and contents together.

Without arguments, git show displays the most recent commit:

git show

Git Diff: Comparing Versions

The git diff command compares different states of your code:

Unstaged changes (working directory vs. staging area):

git diff

Staged changes (staging area vs. last commit):

git diff --staged

Compare two commits:

git diff abc123 def456

Compare branches:

git diff main feature-branch

Reading the Output

Both commands show additions (lines with +) and deletions (lines with -). The context around changes helps you understand what was modified and why.

Practical Use

Use git show when you need to understand a single commit completely. Use git diff when you need to compare two points in time—whether commits, branches, or your current work.

Key Takeaway: git show reveals complete commit details, while git diff compares any two versions of your code, helping you understand what changed, when, and where.