What is git diff?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Git & GitHub basics — a prerequisite for any developer role.
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.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Git & GitHub codebase.