从 git 存储库中删除并忽略所有具有扩展名的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2320895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove and ignore all files that have an extension from a git repository
提问by BenMills
I'm working on a django project with a few other developers and we have recently realized that all the .pwc files in our app cause the commits and repository to be cluttered.
我正在与其他一些开发人员一起进行 django 项目,我们最近意识到我们应用程序中的所有 .pwc 文件都会导致提交和存储库混乱。
Is there any way I can remove all .pwc files from all child directories in my git repository and then ignore them for any future commit?
有什么办法可以从我的 git 存储库中的所有子目录中删除所有 .pwc 文件,然后在以后的任何提交中忽略它们?
回答by Cascabel
Plenty of ways to remove them:
有很多方法可以删除它们:
git ls-files | grep '\.pwc$' | xargs git rm
find . -name *.pwc | xargs git rm
Note: If you haven't committed them, just use rm
, not git rm
.
注意:如果您还没有提交它们,只需使用rm
,而不是git rm
。
To ignore them in the future, simply add *.pwc to the .gitignore. (If you don't have one, create a file named .gitignore at the top level of your repository, and just add a single line saying "*.pwc")
以后要忽略它们,只需将 *.pwc 添加到 .gitignore。(如果没有,请在存储库的顶层创建一个名为 .gitignore 的文件,然后添加一行“*.pwc”)
回答by Fedor
You can also use the following:
您还可以使用以下内容:
git rm -r '*.pwc'
and then make those files ignored by git:
然后让 git 忽略这些文件:
echo '*.pwc' >> .gitignore
The last one is in case if you already have .gitignore file, if not, us single '>' sign.
最后一个是如果你已经有 .gitignore 文件,如果没有,我们用一个 '>' 符号。
回答by Igor Savinkin
In Windowsthis worked for me:
在Windows 中,这对我有用:
git rm -r '*.pwc' -f
And for keeping it in .gitignore
并将其保存在 .gitignore 中
echo '*.pwc' >> .gitignore
回答by davr
Jefromi's answer will remove them for the present and the future...you could also remove them in the past using git filter-branch. Of course this has some other ramifications, like requiring everyone else working on the repo to re-checkout (and possibly rebase any work they haven't pushed to the main repo). Depends how big the PWC files are, you may want to do this if they are wasting a lot of diskspace in your repo (since every time you clone a git repo, you get every file and every revision)
Jefromi 的回答将在现在和未来删除它们……您也可以在过去使用git filter-branch删除它们。当然,这还有其他一些后果,比如要求在 repo 上工作的所有其他人重新结帐(并且可能将他们没有推送到主 repo 的任何工作重新定位)。取决于 PWC 文件有多大,如果它们浪费了存储库中的大量磁盘空间,您可能想要这样做(因为每次克隆 git 存储库时,您都会获得每个文件和每个修订版)