4

Is there a --staged (aka --cached) option for comparing files from a git stash?

Here I'm comparing the most recent commit against a staged file (I'm using the explicit @{} syntax, but I know that @{0} can be inferred):

git diff stash@{0}:spec/blueprints.rb HEAD:spec/blueprints.rb 

And here I'm comparing the stashed file with what's on disk:

git diff stash@{0}:spec/blueprints.rb spec/blueprints.rb 

How can I compare what's currently staged with what's in the stash? This doesn't work:

git diff --staged stash@{0}:spec/blueprints.rb spec/blueprints.rb 

2 Answers 2

6

git diff --cached 'stash@{0}' -- spec/blueprints.rb

... It is possible that quotes are not needed, but you never know how your shell can surprise you.

Sign up to request clarification or add additional context in comments.

Comments

0

:<n>:<path>, e.g. :0:README, :README

A colon, optionally followed by a stage number (0 to 3) and a colon, followed by a path, names a blob object in the index at the given path. A missing stage number (and the colon that follows it) names a stage 0 entry. During a merge, stage 1 is the common ancestor, stage 2 is the target branch’s version (typically the current branch), and stage 3 is the version from the branch which is being merged.

from git help rev-parse

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.