2016-11-04 65 views
0

除了單獨刪除每個文件(即git rm src/classes/Config.php,git rm src/public/ajax.php等等),如何從git中刪除所有這些文件?從git刪除多個文件

[[email protected] 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") 
[[email protected] main]$ 

回答

1

您可以使用git add --updategit add -u總之來分段顯示在「改變,但沒有更新」git status所有更改。

git add階段未跟蹤文件使用此選項,因此它是安全的,當你有很多其他變化(不像git add -A),甚至使用。

這對於像您的情況下您有很多被刪除的文件特別有用。如果您有一些不想分階段進行的更改,則可以使用git reset <path>來取消更改(當然,不需要取消該更改)。

+1

如果我已經使用'git add .'添加它們會怎麼樣?也許'git checkout - *',然後照你說的去做? – user1032531

+0

'git add .'只會添加它在工作目錄中物理找到的文件。因此,您將無法以這種方式展示文件移除。而使用'git add -u'不會影響你已經進行的變更;它* *另外*,所以無論你上演保持上演,但*另外* *「更改但未更新」*部分中的所有更改也被添加。 – poke

+0

沒有試圖檢查出來,但只是'git add -u',並且都很好。 – user1032531

1

您正在尋找git add -u(或--update)。從man git add

這將刪除以及修改索引條目匹配 工作樹,但沒有增加新的文件。