</>
Skip to content
Git lessons (24/44)

Git — Diff

Basic Diff

git diff

Diff Staged

git diff --staged

Diff Between Commits

git diff commit1 commit2

Diff Branches

git diff main..feature

Diff Options

# Word diff
git diff --word-diff

# Stat only
git diff --stat

# Specific file
git diff file.txt

Diff with Context

git diff -U3  # 3 lines of context

Diff Against Branch

git diff main
git diff origin/main

Diff Summary

CommandDescription
git diffWorking vs staged
git diff --stagedStaged vs last commit
git diff HEADWorking vs last commit
git diff branchBranch vs current

Mini Practice

  1. View working changes
  2. View staged changes
  3. Compare commits
  4. Compare branches

Up Next

Continue with Reset — resetting changes.

Related Topics

Frequently Asked Questions about Diff

What is Diff in Git?

Diff is a fundamental concept in Git. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Diff?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Diff.

Why is Diff important in Git?

Diff is essential for Git development. Understanding this concept will help you write better code and solve real-world problems more effectively.