问题:
不小心把python scrapy项目里面一些不需要的目录,如所有pycache目录,提交远端,需要从git删除
调查:
https://stackoverflow.com/questions/7927230/remove-directory-from-remote-repository-after-adding-them-to-gitignore
https://git-scm.com/docs/gitignore
解决:
1
在项目根目录创建.gitignore文件
echo 123 > .gitignore
打开该文件,删除其中全部内容,保存。
找了一份现成的.gitignore
https://github.com/github/gitignore/blob/master/Python.gitignore
拷贝其中内容
粘贴到.gitignore
保存
在其中加上
**/__pycache__/
保存
2
unstage 不要的 pycache:
git rm -r --cache __pycache__
cd spiders
git rm -r --cache __pycache__
3
缓存修改
git commit -m "remove now ignored all cache dirs"
4
提交远端
git push origin master

本文介绍了当误将Python Scrapy项目的pycache目录等不必要的文件提交到Git远端后,如何进行删除的步骤。首先,清空并更新了.gitignore文件,引用了Python的标准.gitignore模板,然后unstage不需要的目录,再提交缓存的更改到远端。
1917

被折叠的 条评论
为什么被折叠?



