138

I staged a lot of files using git add, now I want to see all the files I have staged, without untracked files or changed but unstaged files.

How do I do that? When using git diff --cached I can see the changes of what I just staged. So then I tried using git status --cached but that --cached unfortunately doesn't work on git status.

wjandrea
  • 16,334
  • 5
  • 30
  • 53
Timon de Groot
  • 4,658
  • 4
  • 19
  • 36
  • 5
    simply typing `git status` gives you a list of staged files, a list of modified yet unstaged files, and a list of untracked files. – houtanb Nov 09 '15 at 14:19
  • similar to: https://stackoverflow.com/questions/1587846/how-do-i-show-the-changes-which-have-been-staged/1587877 – rickfoosusa Oct 06 '18 at 23:07
  • @houtanb, `git status` shows you a diff. (It doesn't show you all staged files). – Pacerier Jun 09 '20 at 07:33

2 Answers2

245

The best way to do this is by running the command:

git diff --name-only --cached

When you check the manual you will likely find the following:

--name-only
    Show only names of changed files.

And on the example part of the manual:

git diff --cached
    Changes between the index and your current HEAD.

Combined together you get the changes between the index and your current HEAD and Show only names of changed files.

Update: --staged is also available as an alias for --cached above in more recent git versions.

Brondahl
  • 5,168
  • 1
  • 25
  • 45
Timon de Groot
  • 4,658
  • 4
  • 19
  • 36
  • 14
    This is really useful because it allows you to get a list of filenames that you can then (in my case) pipe to a linter in a pre-commit hook. – walrus Dec 07 '17 at 11:43
  • 5
    If you add files with `git add -N [files]`, this includes those too, even though they are not actually staged for commit yet. As such, it isn't quite exactly what we want for a pre-commit hook. – Pistos Apr 22 '19 at 17:14
  • 1
    re "***last commit***"; Misleading. Better to say `git diff --cached` is short for `git diff --cached head` – Pacerier Jun 09 '20 at 07:53
  • @Pacerier good catch! Fixed. – Brondahl Dec 15 '20 at 18:48
  • This is great. How can I get it to display the paths relative to my current working directory instead of relative to the root directory of the repository? – ibonyun Jan 13 '21 at 18:25
1

You can Try using :- git ls-files -s

  • 3
    This does not provide an answer to the question. [You can search for similar questions](https://stackoverflow.com/search), or refer to the related and linked questions on the right-hand side of the page to find an answer. If you have a related but different question, [ask a new question](https://stackoverflow.com/questions/ask), and include a link to this one to help provide context. See: [Ask questions, get answers, no distractions](https://stackoverflow.com/tour) – jhoepken Jan 19 '21 at 08:37