git ls-files --others --exclude-standard --directory
[a] seems to always give the paths that git status
gives for "Untracked files".
From the same example in the question body:
$ git --version
git version 2.33.0.windows.2
$ ls --recursive
.:
untracked-directory/ untracked-file.txt
./untracked-directory:
untracked-file-1-in-untracked-directory.txt untracked-file-2-in-untracked-directory.txt
$ git status
On branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
untracked-directory/
untracked-file.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git ls-files --others --exclude-standard --directory
untracked-directory/
untracked-file.txt
Note
[a] git ls-files --others --exclude-standard --directory
was adapted from git ls-files --others --exclude-standard
of the accepted answer of "Git: list only "untracked" files (also, custom commands)" by trying out git ls-files --others --exclude-standard
from that answer, noticing it wasn't the exact paths that git status
reports, and then somehow I got to the documentation for git ls-files
, searched the page for "directory", and then I found the --directory
option, and then I tried it out, and it gave the paths that git status
gives, and I have yet to find an example where both git status
and git ls-files --others --exclude-standard --directory
disagree.