Diff a staged file with one in stash

662 views Asked by At

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

There are 2 answers

0
Op De Cirkel On BEST ANSWER

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.

0
jthill On

:<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