2

I’d like Git to show me a list of “new files” in a certain directory, where by “new files” I mean files that are either untracked or which have been added to the index. In other words, I want a command that will do the equivalent of

git status -s some_directory | grep '^\(??\|A \)'

Is there a “git-only” way to do this, or should I just stick with using grep? I’ve tried

git ls-files -o some_directory

which works great for showing the untracked files, but I couldn’t find a flag that would also show files that have been added.

4

1 回答 1

0

要显示已添加的文件:

git diff-index --cached --name-only --diff-filter=A HEAD

不幸的是,我不认为你可以在一个命令中同时获得添加和未跟踪的文件,除非git status像你一样玩一些技巧。git status实际上在幕后运行了几个子命令来获取不同类的文件,所以如果你想要两个输出,你可能只需要使用上面的git ls-files命令。git diff-index

于 2013-06-05T15:37:21.480 回答