其實每次在新建一個庫的時候,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,若還有不完整的,可以自己按照格式添加。