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)
「其他文章」