Adding Only Untracked Files

前端 未结 11 1951
傲寒
傲寒 2020-12-07 07:04

One of the commands I find incredibly useful in Git is git add -u to throw everything but untracked files into the index. Is there an inverse of that? In the la

11条回答
  •  渐次进展
    2020-12-07 07:42

    People have suggested piping the output of git ls-files to git add but this is going to fail in cases where there are filenames containing white space or glob characters such as *.

    The safe way would be to use:

    git ls-files -o --exclude-standard -z | xargs -0 git add
    

    where -z tells git to use \0 line terminators and -0 tells xargs the same. The only disadvantage of this approach is that the -0 option is non-standard, so only some versions of xargs support it.

提交回复
热议问题