git diff --staged Will Diff Files You've Staged vs What's Commit
It compares uncommitted changes vs your latest commmit, --cached does the same thing, it's an alias to --staged.
Quick Jump: Demo Video
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 metions:
–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:
- 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?
Do you use
--cached? Let me know below.