git: list new files only
The commands below no longer give the expected results, I may originally also have made some mistakes. Please double-check your output and the options you are using. Nevertheless: The basic tenet of using diff-filter should still hold true.
Don't use grep to parse git output. Git almost certainly has the things you are looking for built-in (except if you are going for really advanced stuff).
You can use git diff
to show the changes. --name-only
shows only the filenames. --diff-filter=A
lists only the added files.
If you want to see new files you have already added to the index use --cached
, otherwise omit it. To see both diff to HEAD
.
The commands look like this:
git diff --name-only --diff-filter=A --cached # All new files in the index
git diff --name-only --diff-filter=A # All files that are not staged
git diff --name-only --diff-filter=A HEAD # All new files not yet committed
You can use git status --short to get the list of files.
I would use something like git status --porcelain | grep "^A" | cut -c 4-
Instead of parsing the output of "git status", it is probably more elegant to use
git ls-files -o --exclude-standard
As with git status
, ls-files
will produce output relative to your currrent working directory.
You may wish to include the --full-name
option:
git ls-files -o --exclude-standard --full-name