背景:往往我们需要在 push 到 github 时忽略我们的一些隐私的配置文件
1、定义Git全局的 .gitignore 文件
git config --global core.excludesfile .gitignore
2、配置 .gitignore 文件, 如下:忽略 .pyc, .pyo, .pyd, .so 结尾的等文件。
*.py[cod]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
__pycache__
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
venv
app.db
microblog.log*
.env
具体规则可以参考 Git忽略提交规则 - .gitignore配置运维总结
3、清除一下缓存cache,使 .gitignore 生效
git rm -r --cached . #清除缓存
git add . #重新trace file
git commit -m "update .gitignore" #提交和注释
git push origin master #可选,如果需要同步到remote上的话
参考文章:
git 修改.gitignore后生效