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

Comparing Staged Changes

Use `git diff --staged` to review changes that have been added to the staging area before committing.

Comparing Staged Changes

You'll learn how to review exactly what changes are staged and ready to be committed, before you actually commit them.

The Final Check Before Committing

You've used git add to stage your changes, moving them from the working directory into the staging area. But before you run git commit, you want one last look at precisely what you're about to permanently record in your repository's history. This is where git diff --staged comes in.

Think of it like proofreading an email draft one final time before hitting "send." You've already written it (working directory), moved it to your drafts folder (staging area), but now you want to review exactly what's in that draft before it goes out permanently (commit).

How It Works

git diff --staged

This command shows you the differences between the staging area and your last commit. It answers the question: "What will actually be included in my next commit?"

The output displays:

  • Lines you've added to staged files (prefixed with +)
  • Lines you've removed from staged files (prefixed with -)
  • Which files have staged changes

This is different from git diff (no flags), which shows unstaged changes in your working directory.

Why This Matters for Data Scientists

Before committing changes to analysis scripts, model code, or configuration files, you want to verify you're not accidentally including:

  • Debugging print statements
  • Hardcoded file paths
  • Temporary experimental code
  • Sensitive credentials

The --staged flag gives you that critical final review of what's actually going into version control history.

Key Takeaway: Use git diff --staged as your final checkpoint to review exactly what changes are in the staging area before committing them to your repository's permanent history.