Git list of staged files

GitGit DiffGit StatusGit Stage

Git Problem Overview


I staged a lot of files using git add, and 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.

Git Solutions


Solution 1 - Git

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.

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

Solution 2 - Git

You can try using git ls-files -s

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTimon de GrootView Question on Stackoverflow
Solution 1 - GitTimon de GrootView Answer on Stackoverflow
Solution 2 - Gitsudhanshu tiwariView Answer on Stackoverflow