What is git diff?
Answer
git diff shows the difference (changes) between various states of files. Common usages: git diff — shows unstaged changes (working directory vs last commit for tracked files); git diff --staged / --cached — shows staged changes (what will be committed); git diff HEAD — shows all changes (staged + unstaged) vs last commit; git diff branch1 branch2 — diff between two branches; git diff commit1 commit2 — diff between two commits; git diff HEAD~3 — changes since 3 commits ago; git diff file.txt — diff for a specific file only. Output format: lines starting with + (green) are additions, - (red) are deletions, context lines have no prefix. git diff --stat — summary of changed files and line counts. git diff --word-diff — shows word-level changes instead of line-level (useful for prose). External diff tools: git difftool opens a visual diff tool (VS Code, vimdiff, meld). Understanding git diff is essential for reviewing changes before committing and for code review.