Skip to main content
⚡ OpenDevDocs
Git
gitgitGuideBeginner

git diff — Inspecting File Changes

Comparing changes in Git: working directory vs staging area, staged changes (--staged), comparing commits, and comparing branches.

Verified: 2026-09-30
Platforms:
all
#git#diff#staging#inspection

git diff — Inspecting File Changes

The git diff command computes and displays changes between files in your working directory, the staging area, historical commits, or distinct Git branches.


1. Core Comparison Commands

CommandCompares What?
git diffUnstaged changes in working directory vs. Staging Area (the index).
git diff --staged (or --cached)Staged changes in the index vs. the last commit (HEAD).
git diff HEADALL changes (staged + unstaged) vs. the last commit.
git diff commitA..commitBDifferences between two specific commit SHA hashes.
git diff main..feature-branchDifferences between the tips of two branches.

2. Reading Git Diff Output

diff --git a/app/page.tsx b/app/page.tsx
index 8a34bc1..9f8012e 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -12,4 +12,4 @@ export default function Page() {
-  const title = "Docs";
+  const title = "OpenDevDocs";
  • --- a/app/page.tsx: Original version of the file.
  • +++ b/app/page.tsx: New modified version.
  • @@ -12,4 +12,4 @@: Line numbers and range modified in original vs. new file.
  • - (Red): Deleted lines.
  • + (Green): Added lines.

3. Comparing Specific Files or Summary

# Compare only a single file:
git diff src/components/Header.tsx

# Word-level diff rather than line-level diff:
git diff --word-diff

# Show summary of modified files and inserted/deleted line counts:
git diff --stat

On this page