简体   繁体   English

快速从git存储库中删除所有文件

[英]Quickly remove all files from a git repository

In a repository I have there are lots of unnecessary files, which I would like to remove from the repo and only keep locally. 在存储库中,我有很多不必要的文件,我想从存储库中删除这些文件,仅将其保存在本地。 I understand that this is done by: 我了解这是通过以下方式完成的:

git rm --cached a_file

... or with -r in case it's a folder. ...或使用-r (如果它是文件夹)。

Now, it's easier to remove everything and add the few files I need. 现在,删除所有内容并添加一些我需要的文件变得更加容易。 If I use * , git rightly complains when it's given files that are not in the repo, but in the same local folder. 如果我使用* ,当给定的文件不在仓库中,而是在相同的本地文件夹中时,git会正确地抱怨。

How should I proceed? 我应该如何进行?

EDIT: Using the -f flag won't work either: 编辑:使用-f标志将不起作用:

$ git rm --cached -fr *
fatal: pathspec 'somefile' did not match any files

The --ignore-unmatch flag for git rm does exactly what you want from what I can tell. git rm--ignore-unmatch标志完全--ignore-unmatch我的要求。

$ git rm --cached bla
fatal: pathspec 'bla' did not match any files
$ git rm --cached --ignore-unmatch bla
$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM