jaygooby
jaygooby

Reputation: 2536

Diff a staged file with one in stash

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

Upvotes: 4

Views: 667

Answers (2)

Op De Cirkel
Op De Cirkel

Reputation: 29463

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.

Upvotes: 6

jthill
jthill

Reputation: 60235

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

Upvotes: 0

Related Questions