Compare Changes with Diff
Diff prints the lines that changed. It compares two states and shows only the difference.
See the unstaged change
One line is new. The plus sign marks it.
$ git diffSee the staged change
After staging, the plain form prints nothing. The staged form shows the same line.
$ git add notes.txt
$ git diff --stagedSee everything against HEAD
HEAD covers staged and unstaged changes together.
$ git diff HEADExample
$ git diffKey points
- Diff with no extra words compares the files with the last snapshot.
- A plus line is new. A minus line is gone.
- Diff after staging prints nothing, because the changes moved.
- Diff with --staged compares the staging area with the last snapshot.
- Diff with HEAD compares the files with the newest snapshot.
- HEAD is the newest snapshot, so HEAD covers staged and unstaged changes together.
- Read diffs before every commit. Surprises hide there.
Here, one line is new. The plus sign marks it. Everything else matches the last snapshot.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which command shows staged changes?