Git add only all new files, not modified files [duplicate]

瘦欲@ 提交于 2019-11-27 20:44:32

Maybe

git add $(git ls-files -o --exclude-standard)

git ls-files lets you list the files managed by git, filtered by some options. -o in this case filters it to only show "others (i.e. untracked files)"

The $(...) statement passes the return value of that command as an argument to git add.

You can use short mode of git status (see man git-status(1)), which gives the following output:

Without short mode:

$ 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")

With short mode:

$ git status -s
 M application/models/membre_model.php
?? README
?? application/libraries/Membres_exception.php

Then using grep, awk and xarg, you can add the files where the first column is ??.

$ git status -s | grep '??' | awk '{ print $2 }' | xargs git add 

and see that it worked:

$ 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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!