Lesson 12 +15 XP

Git Diff

Git Diff

git diff shows the exact changes you have made, line by line.

See unstaged changes

git diff

This shows the difference between your working directory and the staging area, meaning changes you have not staged yet.

See staged changes

git diff --staged

This shows what is ready to be committed. It compares the staging area with the last commit.

Understand the output

git diff uses two colors:

  • Red lines were removed.
  • Green lines were added.

Each change shows the file name, line numbers, and the old and new lines.

Compare two commits

git diff hash1 hash2

This compares any two commits in your history.

Check a single file

git diff -- index.html

The -- separates options from the file name.

TL;DR

  • git diff shows unstaged changes.
  • git diff --staged shows what is ready to commit.
  • Red lines are removed, green lines are added.
  • git diff hash1 hash2 compares two commits.