4

这是我的 git 状态:

# On branch create-views-question
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    solr/data/development/index/_0.fdt
#   deleted:    solr/data/development/index/_0.fdx
#   deleted:    solr/data/development/index/_0.fnm
#   deleted:    solr/data/development/index/_0.frq
...

目前,我曾经git rm一个接一个地删除文件,有没有另一种方法可以同时删除它们?

4

3 回答 3

9

在这种情况下,你可以做

git rm 'solr/data/development/index/_0.*'

注意'标记以防止外壳扩展,而是*直接将其传递给 git。

这是一个例子:

graphite> git status
# On branch master
# Changes not staged for commit:
#   deleted:    a
#   deleted:    b
#
no changes added to commit
graphite> git rm '*'
rm 'a'
rm 'b'
graphite> git status
# On branch master
# Changes to be committed:
#   deleted:    a
#   deleted:    b
#
于 2012-11-02T21:05:22.177 回答
6

您还可以使用:

git rm --cached `git status | grep deleted | sed 's#^.*:##'`

这删除了所有带有deleted:前缀的文件git status

于 2014-04-28T03:23:25.243 回答
0

就个人而言,如果我只是想让我的本地看起来像远程,我喜欢这样做:

git reset --hard upstream/BRANCHNAME
于 2021-08-09T18:39:07.997 回答