Video in progress

Junior 🌿 Git

What do `git diff` and `git diff --staged` show?

Plain git diff shows changes that have not been added to staging yet. git diff --staged (or --cached) shows the changes that were git added, that is, the ones that will go into the next commit.

📖 Answer

Many beginners are surprised that git diff comes out empty after git add. The reason is simple: the change is in staging now, and a different command shows it.

git diff               # working directory vs staging
git diff --staged      # staging vs the last commit
git diff HEAD          # both together: everything on disk vs the last commit
git diff main..feature # the difference between two branches

It is a good habit to look over git diff --staged before committing. That is where you catch a stray System.out.println, a port changed for debugging, or a password.