Git & GitHub Interview Question #17
What does git diff do?
Git Fundamentals, Repository, Working Tree, Staging, Commits & Branch Basics Junior Beginner
Quick Interview Answer
git diff shows differences between Git states. Without arguments, it commonly shows unstaged changes in the working tree relative to the index. With --staged, it shows staged changes relative to the current commit.
Detailed Explanation
git diff shows differences between Git states. Without arguments, it commonly shows unstaged changes in the working tree relative to the index. With --staged, it shows staged changes relative to the current commit.
It is useful before committing because it lets a developer review exactly what has changed and what has been staged.
Code Example
git diff
git diff --staged