Git:仅列出“未跟踪”文件(也是自定义命令) [英] Git: list only "untracked" files (also, custom commands)
问题描述
有没有办法像 git ls-files
这样的命令只显示未跟踪的文件?
Is there a way to use a command like git ls-files
to show only untracked 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
我可以找到 -o
选项添加到 git ls-files
,但这不是我想要的,因为它也显示被忽略的文件。我也能够想出以下冗长而难看的命令:
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. I was also able to come up with the following long and ugly command:
git status --porcelain | grep '^??' | cut -c4- | xargs git add
好像有一个更好的命令可以在这里使用。如果没有,我该如何创建自定义的git命令?
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?
推荐答案
列出未记录的文件尝试:
To list untracked files try:
git ls-files --others --exclude-standard
添加未跟踪文件的好别名:
Nice alias for adding untracked files:
au = !git add $(git ls-files -o --exclude-standard)
编辑:参考: git-ls-files
这篇关于Git:仅列出“未跟踪”文件(也是自定义命令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!