其实每次在新建一个库的时候,github上都有勾选创建.gitignore的选项,可以自己选择语言,python,java等等,那我每次都勾选了。然后在做Django项目的时候,加了一个忽略.idea的文件夹。
.gitignore
# Byte-compiled / optimized / DLL files __pycache__/ .idea *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # pyenv .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. #Pipfile.lock # PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff celerybeat-schedule celerybeat.pid # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/
一般呢,如果是忽略文件夹的话是会加上/的,不加好像也行,自己可以用git status看看。
./一般是当前路径为起点。
../一般是上层路径为起点
*一般表任意。如*.txt表示任意以txt为后缀的文件
主要辨别一点吧。
./dist/指的是忽略当前文件夹里面的dist文件夹
dist/指的是忽略所有的dist文件夹,不止当前目录,还包括下层目录,下下层目录等等。
若想上传gitlab,或其他git平台,可以直接复制这份.gitignore,若还有不完整的,可以自己按照格式添加。