Git list of staged files
187,923
Solution 1
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
You can try using git ls-files -s
Related videos on Youtube
Author by
Timon de Groot
Updated on August 19, 2022Comments
-
Timon de Groot over 1 year
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 usinggit status --cached
, but that--cached
unfortunately doesn't work ongit status
.-
houtanb over 8 yearssimply typing
git status
gives you a list of staged files, a list of modified yet unstaged files, and a list of untracked files.
-
-
walrus over 6 yearsThis 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.
-
Pistos about 5 yearsIf 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. -
Pacerier almost 4 yearsre "last commit"; Misleading. Better to say
git diff --cached
is short forgit diff --cached head
-
ibonyun over 3 yearsThis 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?
-
Peter Mortensen over 2 yearsThis seems to list all tracked files (staged or or unstaged), not the staged files (that the question is about). This does not answer the question: "to see all the files I have staged ... without ... changed but unstaged files."). This answer is blatantly wrong. Why is this being voted up when it doesn't answer the question (it answers some other question)?
-
Peter Mortensen over 2 yearsThis does not answer the question and is completely wrong. It answers some other question. Can you delete it, please? Thanks in advance.
-
General Grievance over 2 yearsAmplifying information: stackoverflow.com/questions/28159325/…
-
pyrsmk over 2 yearsMost of the time, you would remove deleted files from the list because you're passing this file list to a command that expects that all files exist. To remove deleted files from the list, you could do :
git --no-pager diff --name-only --cached --diff-filter=AM
.