Git只添加所有新文件,而不是修改文件

And*_*erg 13 git git-add

有没有办法只添加新文件而不是用git添加修改过的文件?也就是说,使用git status列出未跟踪的文件.

除了当然分别添加每个文件.

在我的情况下,这不是绝对必要的,对我来说真正的问题在这里得到解答:如何使git-diff和git log忽略新的和删除的文件?

也就是说,不要在新文件上显示差异,所以我更多地问这个,因为我无法在任何地方找到答案.

Nil*_*ner 22

也许

git add $(git ls-files -o --exclude-standard)
Run Code Online (Sandbox Code Playgroud)

git ls-files让你列出由git管理的文件,通过一些选项进行筛选.-o在这种情况下过滤它只显示"其他(即未跟踪的文件)"

$(...)语句将该命令的返回值作为参数传递给git add.


Aif*_*Aif 5

您可以使用git status的简短模式(请参阅man git-status(1)),该模式提供以下输出:

没有短模式:

$ git status

...


# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   README
#   application/libraries/Membres_exception.php
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)

使用短模式:

$ git status -s
 M application/models/membre_model.php
?? README
?? application/libraries/Membres_exception.php
Run Code Online (Sandbox Code Playgroud)

然后使用grep,awk和xarg,可以将文件添加到第一列??

$ git status -s | grep '??' | awk '{ print $2 }' | xargs git add 
Run Code Online (Sandbox Code Playgroud)

并查看它的工作原理:

$ git status
# On branch new
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   README
#   new file:   application/libraries/Membres_exception.php
Run Code Online (Sandbox Code Playgroud)