What are `git status` and `git diff` for, and how do they differ?
Show answer — try answering out loud first
git status tells you the state of your files: which branch you're on, what's staged, what's modified, and what's untracked. git diff shows you the exact content of the changes, line by line. git diff compares working vs staging, and git diff --staged compares staging vs the last commit.
They're your two tools for knowing "what's going on" before committing.
git status: the overview. It tells you which files changed and in which area they are (staged or not, tracked or untracked). It doesn't show the content of the changes, only the names and their state.git diff: the detail. It shows the lines you added (+) and removed (-).git diff(with nothing): compares the working directory against staging → the changes you haven'tadded yet.git diff --staged(or--cached): compares staging against the last commit → what you're about to commit.
Practical rule: status for the big picture, diff to review exactly what you're going to save.
# General overview of the repo
git status
# On branch main
# Changes to be committed: (green, staged)
# Changes not staged for commit: (red, not staged)
# Untracked files: (red, new)
# Short summary version
git status -s
# M archivo.txt (modified, not staged)
# M otro.txt (modified, staged)
# ?? nuevo.txt (untracked)
# View changes that are NOT staged yet
git diff
# View changes that ARE already staged (what will be committed)
git diff --staged
# Compare two commits
git diff abc1234 def5678
Believing that git diff shows all the changes. By default, git diff does not show changes that are already staged: for those you need git diff --staged. Many juniors run git add ., then git diff to review, see that it comes back empty, and get confused, when the right command would be git diff --staged.
"
git statusgives me the overview: which branch I'm on and which files are staged, modified, or untracked, but only the names.git diffshows me the content of the changes line by line. Plaingit diffcompares the working directory with staging, i.e. what I haven't staged yet; andgit diff --stagedcompares staging with the last commit, i.e. what I'm going to save. I use status for the big picture and diff to review the detail before committing."
You ran git add . and want to review exactly which lines you're going to commit. Which command do you use?
See answer
git diff --staged (equivalent to git diff --cached). Since the changes are already in the staging area, plain git diff would come back empty; you need --staged to compare staging against the last commit and see exactly what's going to be saved.