除了单独删除每个文件(例如git rm src/classes/Config.php
,git rm src/public/ajax.php
等等)之外,如何从git中删除所有这些文件?
[Michael@devserver main]$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: src/classes/Config.php
# deleted: src/public/ajax.php
# deleted: src/public/fileuploader.php
# deleted: src/public/index2.php
# deleted: src/public/json_encode.php
# deleted: src/public/petstore.json
# deleted: src/public/resources/index.php
# deleted: src/public/slimttest.php
# deleted: src/public/temp.php
# deleted: src/public/test.php
# deleted: src/public/test/bla.php
# deleted: src/public/test/file1.php
# deleted: src/public/test/file2.php
# deleted: src/public/test2.php
# deleted: src/public/testAPI.php
# deleted: src/public/testAPI2.php
# deleted: src/public/test_original.php
# deleted: src/public/testfile.php
# deleted: temporary.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
[Michael@devserver main]$
答案 0 :(得分:1)
您正在寻找git add -u
(或--update
)。来自man git add
:
这将删除并修改索引条目以匹配 工作树,但没有添加新文件。
答案 1 :(得分:1)
您可以简短地使用git add --update
或git add -u
来暂存{{1>}中“已更改但未更新”部分中显示的所有更改。< / p>
在git add
上使用此选项将不暂存未跟踪文件,因此即使您有许多其他更改(与git status
不同)也可以安全使用。
这对于像你这样有很多被删除文件的情况特别有用。如果您有一些不想进行的更改,则可以使用git add -A
来取消更改(不会撤消当前的更改)。