How to show diff of a staged deleted file?

git

Solution

Your first approach is almost right, it just has two small problems.

Firstly, since you haven't committed yet, the last version that still has the `thing.scala` file is `HEAD`. `HEAD~1` is the version before that.

Secondly, the syntax to show a file from a specific commit is `git show <commit>:<file>`.

So the correct command is:

git show HEAD:thing.scala

The documentation mentions this syntax in gitrevisions:

<rev>:<path>, e.g. HEAD:README, :README, master:./README

A suffix : followed by a path names the blob or tree at the given path in the tree-ish object named by the part before the colon. :path (with an empty part before the colon) is a special case of the syntax described next: content recorded in the index at the given path. A path starting with ./ or ../ is relative to the current working directory. The given path will be converted to be relative to the working tree’s root directory. This is most useful to address a blob or tree from a commit or tree that has the same tree structure as the working tree.

As for `git diff --cached`: the arguments that follow are interpreted as file names only if they exist as files. Since you removed the file, that doesn't apply. You can force arguments to be interpreted as file names by using `--`:

git diff --cached -- thing.scala

Problem

Here is the status: ``` On branch howard Your branch is up-to-date with 'origin/howard'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) deleted: thing.scala (and other changed files) ``` If I do `git diff --cached`, it shows the content of `thing.scala` as well as other diffs. But I am interested to see only the deleted file's content. How to do so in git? The following attempts don't work: ``` git show HEAD~1 thing.scala git diff --cached thing.scala ```

Original source