Code investigation skills: changes between areas with git diff, differences between two commits, inspecting commit details with git show, and identifying the author of each line of code using git blame.

In episode 4 you started building a clean commit history. As the history grows, critical questions arise: what exactly changed in this commit? Does the staging area match expectations? Who wrote this problematic line of code?
This episode is investigation training. Three commands — git diff, git show, and git blame — are the detective tools you will use nearly every day, whether during code review, debugging, or figuring out why a line of code exists.
git diff without arguments compares the working directory with the staging area — showing changes that have not been staged yet.
git diff
diff --git a/index.html b/index.html
--- a/index.html
+++ b/index.html
@@ -1 +1 @@
-<h1>Halo Dunia</h1>
+<h1>Halo, Git!</h1>How to read the diff output:
--- line is the old version, the +++ line is the new version.- were deleted, lines marked + were added.To see changes that have been staged, use git diff --staged (synonym: --cached):
git diff --staged
git diff --cachedMeanwhile, git diff HEAD compares both at once: the entire difference between the working tree and the last commit — the combined staged and unstaged changes.
To see the difference between any two commits, provide two hashes:
git diff 9c4a2d6e b8e1f3a7This command shows all changes from the first commit to the second — very useful during code review to see what changed in a single pull request.
To avoid confusion, the summary below orders the comparisons from the most "fresh" to the most historical:
| Command | Compares |
|---|---|
git diff | Working directory vs staging area |
git diff --staged | Staging area vs last commit |
git diff HEAD | Working tree vs last commit (combined) |
git diff <c1> <c2> | Two commits directly |
Tip
Get in the habit of checking git diff before committing. It is like checking your work before submitting — preventing build files or secrets from accidentally getting staged. Meanwhile, git diff --staged is the final check before the snapshot is locked into a commit.
git show <hash> displays one commit in full: metadata (author, date, message) plus the diff of changes it introduced. This is the fastest window into understanding a commit's content.
git show b8e1f3a7
commit b8e1f3a7
Author: Arman Dwi Pangestu
feat: tambah halaman logingit show HEAD shows the last commit; git show HEAD~1 shows the commit one before HEAD. Without a hash argument, git show displays the currently active commit (HEAD).
git blame <file> answers the question: who changed this line, when, and in which commit?
git blame login.js
b8e1f3a7 (Arman Dwi Pangestu 2026-08-01 10:22) function login(user) {
b8e1f3a7 (Arman Dwi Pangestu 2026-08-01 10:22) if (!user.password) {
7a2c9d1e (Rina Sari 2026-07-28 14:05) throw new Error("password wajib");Each line is marked with the commit hash, author, date, and the line's content. Use git blame when you find a bug: trace the commit that introduced the problematic line, then look at the change context at that time — often the reason becomes clear.
Note
git blame maps a line to the last commit that touched it — it is not about "blaming" someone, but tracing the origin of code. Think constructively: it is a tool for understanding, not judging.
These three commands complement each other for different scenarios:
git diff to check the raw changes, then git diff --staged to make sure the staging area is free of anything unwanted.git diff <c1> <c2> to see what changed across the whole pull request; git show <hash> to assess one commit in depth.git blame <file> finds the commit that introduced the bug, then git show <hash> opens the full change context of that commit.Important
The combination of git blame followed by git show is Git's most powerful investigation workflow: from a single problematic line of code, you can trace the entire history to the root cause. Practice this workflow until it becomes second nature.
Episode 5 recap:
git diff compares the working directory vs staging area; git diff --staged for already staged changes.git diff HEAD combines both; git diff <commit1> <commit2> compares two commits.git show <hash> opens the full details of one commit.git blame <file> traces the author and origin of every line of code.In episode 6 we enter the most anticipated new chapter: branching — understanding that a branch is just a lightweight pointer, creating and switching branches with git switch, and renaming and deleting branches. With that, you are ready to work on features without disturbing the main work. See you there!