Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

git diff --staged Will Diff Files You've Staged vs What's Commit

git-diff-staged-will-diff-files-you-have-vs-what-is-commit.jpg

It compares uncommitted changes vs your latest commmit, --cached does the same thing, it's an alias to --staged.

Quick Jump:

I use git diff a lot in my day to day.

Sometimes I want to see a diff of changes I’ve already staged using git add -p vs the latest commit. For that you can use git diff --staged or git diff --cached.

The official git diff documentation mentions:

–staged is a synonym of –cached

I prefer the --staged flag since it’s more descriptive of what the command does based on it being related to changes or files you’ve staged. Based on the doc’s wording it sounds like --staged was added at a later time.

The video below goes over using this command:

# Demo Video

Timestamps

  • 0:11 – Going over the example repo
  • 0:49 – Using git diff without any flags when you staged changes
  • 1:23 – Using the –staged flag to see a diff of staged changes
  • 1:56 – There’s also the –cached flag which does the same thing
  • 2:50 – Do you prefer using –staged or –cached?

Reference Links

Do you use --staged or --cached? Let me know below.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per year (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments