#1 使用模板
刚学习Git时,知道Git的.gitignore
会忽略掉文件或文件夹。但是,项目多了,就会存在一个问题:
每次新创建一个项目时,都要创建一次.gitignore
,还时不时就得修改下。
那么,有不有办法能够免去或者极大减少这个工作量呢?
幸好,是有的。
有人根据编程语言,集合了常用的.gitignore
文件配置,并且发布出来了。
使用的时候只需要复制一份相应的东西到项目里即可。
模板的下载地址是:
git clone https://gitcode.com/github/gitignore.git
几乎每一种变成语言的模板都有。以Python的举例,包含了Django、Flask等常见的框架,venv等常见的虚拟环境:
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
...
# PyInstaller
...
# Installer logs
# Unit test / coverage reports
...
# Translations
...
# Django stuff:
...
# Flask stuff:
...
# Scrapy stuff:
...
# Sphinx documentation
...
# PyBuilder
...
# Jupyter Notebook
...
# IPython
...
# pyenv
...
# pipenv
...
# poetry
...
# pdm
...
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
...
# Celery stuff
...
# SageMath parsed files
...
# Environments
...
# Spyder project settings
...
# Rope project settings
...
# mkdocs documentation
...
# mypy
...
# Pyre type checker
...
# pytype static type analyzer
...
# Cython debug symbols
...
# PyCharm
...
#2 使用global文件
在上述Python的ignore文件里,关于PyCharm那段是这么说的:
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
即,PyCharm的ignore应当设置为global ignore文件。
那么,如何设置global ignore文件呢?
首先,我们要在用户主目录创建一个 .gitignore_global
文件,并填写相关内容
其次,要通过如下命令告诉Git使用这个文件作为global ignore文件:
git config --global core.excludesfile ~/.gitignore_global
再接下来,所有新的或现存的 Git 仓库都会自动应用这个文件里的内容
还是以上面的例子,想要将PyCharm自动生成的文件设置为global ignore文件,只需要在第一步下载的仓库里执行两条语句即可:
$ cp Global/JetBrains.gitignore ~/.gitignore_global
$ git config --global core.excludesfile ~/.gitignore_global
原文始发于微信公众号(Know Why It):.gitignore的高级用法二则
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/276229.html