Consider the following command:
git clean -n -x -d
This produces output of the following form:
Would remove path/to/file/1
Would remove untracked/directory
I would like to run a different command X on these files, but the extra Would remove
prefix is not useful.
I could run sed
or cut
to kill this prefix.
git clean -n -x -d | cut -c 14-
However, I'm curious about whether there's a lower level git
plumbing command I can use the get the output I want without starting another process.
git ls-files --other
seemed promising, but unfortunately, its output includes all the files, instead of just the directory containing all the files.
path/to/file/1
untracked/directory/file1
untracked/directory/file2
...
Is there a low-level git command to replicate the output of git clean
above without the extra prefix, or is my cleanest option just to cut
out the prefix?
CodePudding user response:
If you need to get near git's plumbing, you can list untracked files with:
git ls-files --others
Alternatively, you can stick with commonly known tools, i.e.
git status --short --ignored | grep '!!\|??'
Documentation: