Course contentsShow
← Data Science
Lesson 2001 of 2,14546. Version Control with GitFree lesson

Comparing Working Directory Changes

Use `git diff` to see line-by-line changes in your working directory that haven't been staged yet.

Comparing Working Directory Changes

You'll learn how to see exactly what you've changed in your files before deciding to stage them.

The Core Idea

When you're working on data science code—maybe tweaking a model, refining data cleaning logic, or updating analysis parameters—you'll modify files in your working directory. Before staging those changes with git add, you often want to review exactly what changed. That's where git diff comes in.

Think of git diff as a "red pen markup" view. It shows you line-by-line differences between your current working files and what Git last knew about them (the last commit). Lines you removed appear marked with -, and lines you added appear with +.

How It Works

Simply run:

git diff

This command displays unstaged changes only—modifications you've made but haven't yet added to the staging area. You'll see output showing:

  • Which files changed
  • Specific lines removed (prefixed with -)
  • Specific lines added (prefixed with +)
  • Context lines around changes (unchanged, for reference)

For example, if you changed a hyperparameter in a training script from learning_rate = 0.01 to learning_rate = 0.001, git diff shows both lines with clear before/after context.

Why This Matters

Before committing, you want to verify you're including only intentional changes—not debug print statements, temporary code, or accidental deletions. git diff acts as your quality control checkpoint, letting you catch mistakes before they become permanent history.

It's especially valuable when you've been working for hours and can't quite remember everything you modified. A quick git diff refreshes your memory and helps you write accurate commit messages.

Key Takeaway: git diff shows line-by-line unstaged changes in your working directory, letting you review modifications before staging them—essential for maintaining clean, intentional version control history.