Skip to content

git diff — Seeing What Changed

git status tells you which files changed. git diff tells you what changed — the exact lines added, removed, or modified. It is the tool you use before staging to review your own work, and before committing to make sure what you are about to save is intentional.

git diff with no arguments shows changes in your working tree that have not been staged yet — the difference between your current files and the last staged version (or the last commit if nothing is staged).

Make a change to pine-ridge.txt in your git-practice folder without staging it, then run:

Terminal window
git diff

You will see output like this:

diff --git a/pine-ridge.txt b/pine-ridge.txt
index 8d6a2f1..c4b3e7a 100644
--- a/pine-ridge.txt
+++ b/pine-ridge.txt
@@ -1 +1,2 @@
Tour notes for Pine Ridge
+Best time to visit: spring or fall

The diff format appears throughout Git. Here is what each part means:

diff --git a/pine-ridge.txt b/pine-ridge.txt

The file being compared. a/ is the “before” version, b/ is the “after” version.

--- a/pine-ridge.txt
+++ b/pine-ridge.txt

Markers for the two versions. Lines starting with --- are from the old version; lines starting with +++ are from the new version.

@@ -1 +1,2 @@

The hunk header. -1 means the old version had 1 line starting at line 1. +1,2 means the new version has 2 lines starting at line 1.

Tour notes for Pine Ridge
+Best time to visit: spring or fall

The actual content. Lines with no prefix are context (unchanged). Lines with + are additions. Lines with - are removals.

When a line is modified, Git shows it as one removal and one addition:

Tour notes for Pine Ridge
Tour notes for Pine Ridge Loop

git diff only shows unstaged changes. To see what is in the staging area — what will go into the next commit — add the --staged flag:

Terminal window
git diff --staged

This shows the difference between the staging area and the last commit.

CommandWhat it compares
git diffWorking tree vs. staging area (unstaged changes)
git diff --stagedStaging area vs. last commit (staged changes)
git diff HEADWorking tree vs. last commit (all changes, staged and unstaged)

To diff a single file instead of all changes:

Terminal window
git diff pine-ridge.txt
git diff --staged pine-ridge.txt

You can diff any two commits using their hashes:

Terminal window
git diff a3f8c12 b7e9d03

Or compare a commit to the current state:

Terminal window
git diff a3f8c12

You will use this more in Module 04 when working with history.

If nothing has changed since the last commit or stage, git diff produces no output and returns immediately. This is not an error — it means there is nothing to show.

  1. In your git-practice folder, edit pine-ridge.txt to add a new line and change an existing one.

  2. Run git diff and read the output. Identify the hunk header, context lines, added lines (+), and removed lines (-).

  3. Stage the file:

Terminal window
git add pine-ridge.txt
  1. Run git diff. Notice there is no output — the unstaged diff is empty because you staged everything.

  2. Run git diff --staged. Now you see the staged changes — the same diff you saw before staging.

  3. Make one more edit to pine-ridge.txt without staging it. Now run both git diff and git diff --staged and compare what each shows.

  • git diff shows unstaged changes — the difference between your working tree and the staging area (or last commit).
  • git diff --staged shows staged changes — what will go into the next commit.
  • git diff HEAD shows all changes, staged and unstaged, compared to the last commit.
  • The unified diff format: - for removed lines, + for added lines, no prefix for unchanged context.
  • The @@ hunk header tells you which line numbers are affected.
  • Diffing a specific file: git diff <filename>.

Next: a closer look at the staging area — how to stage partial changes, unstage files, and check exactly what is staged before you commit.