Git:仅列出“未跟踪”的文件(还有自定义命令) - Git: list only “untracked” files (also, custom commands)

语言: CN / TW / HK

问题:

Is there a way to use a command like git ls-files to show only untracked files?有没有办法使用像git ls-files这样的命令来只显示未跟踪的文件?

The reason I'm asking is because I use the following command to process all deleted files:我问的原因是因为我使用以下命令来处理所有已删除的文件:

git ls-files -d | xargs git rm

I'd like something similar for untracked files:对于未跟踪的文件,我想要类似的东西:

git some-command --some-options | xargs git add

I was able to find the -o option to git ls-files , but this isn't what I want because it also shows ignored files.我能够找到git ls-files-o选项,但这不是我想要的,因为它还显示被忽略的文件。 I was also able to come up with the following long and ugly command:我还想出了以下又长又丑的命令:

git status --porcelain | grep '^??' | cut -c4- | xargs git add

It seems like there's got to be a better command I can use here.似乎必须有一个更好的命令我可以在这里使用。 And if there isn't, how do I create custom git commands?如果没有,我该如何创建自定义 git 命令?


解决方案:

参考一: http://stackoom.com/question/Fwtd
参考二: Git: list only “untracked” files (also, custom commands)
「其他文章」