9. Every diff compares two of the three places
git diff compares the working tree with the index, git diff --staged compares the index with HEAD, and git status reports both gaps.

9. Every diff compares two of the three places

git diff compares the working tree with the index, git diff --staged compares the index with HEAD, and git status reports both gaps.

"My change disappeared from git diff" is the most common index confusion.

Three places. A diff is always a comparison between two of them.

git diff compares your files with the tray. It shows what you have not added yet.

git diff, staged, compares the tray with the last commit. It shows what the next commit will contain.

Add a file, and git diff goes quiet about it. The change did not vanish. It moved to the other gap.

git status reports both gaps at once. Changes not staged. Changes to be committed.

Check yourself. You added a file and git diff shows nothing. Where is the change?

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Attributes
name
9. Every diff compares two of the three places
summary
git diff compares the working tree with the index, git diff --staged compares the index with HEAD, and git status reports both gaps.