赞
踩
语言框架:python-flask
IDE:JetBrains IDEA
工具:git
系统:win11
python-flask在往gitee仓库上传代码的时候,官网下载的.gitignore文件不起作用,根本删除不了不想要的文件。
以python-flask项目举例。
打开下方网址:https://github.com/github/gitignore
下载想要的.ignore文件,我要上传的python-flask,下载Python.gitignore,文件名字改成:.gitignore,放至要上传仓库的代码的主目录。
- # 文件名称 .gitignore
- # Byte-compiled / optimized / DLL files
- __pycache__/
- *.py[cod]
- *$py.class
-
- # C extensions
- *.so
-
- # Distribution / packaging
- .Python
- build/
- develop-eggs/
- dist/
- downloads/
- eggs/
- .eggs/
- lib/
- lib64/
- parts/
- sdist/
- var/
- wheels/
- 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/
- cover/
-
- # 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
- .pybuilder/
- target/
-
- # Jupyter Notebook
- .ipynb_checkpoints
-
- # IPython
- profile_default/
- ipython_config.py
-
- # pyenv
- # For a library or package, you might want to ignore these files since the code is
- # intended to run in multiple environments; otherwise, check them in:
- # .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
-
- # poetry
- # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
- # This is especially recommended for binary packages to ensure reproducibility, and is more
- # commonly ignored for libraries.
- # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
- #poetry.lock
-
- # pdm
- # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
- #pdm.lock
- # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
- # in version control.
- # https://pdm.fming.dev/#use-with-ide
- .pdm.toml
-
- # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
- __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/
-
- # pytype static type analyzer
- .pytype/
-
- # Cython debug symbols
- cython_debug/
-
- # 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/
- migrations/
注意:以上代码是我修改过的,我修改了最后两行。
.gitignore,放至要上传仓库的代码的主目录。
官网下载的gitignore文件删除不掉JetBrains IDEA编译器产生的.idea 和migrations文件夹。
在.gitignore文件中添加以下两行即可,也可以其他删除的文件或文件夹,直接复制我的代码即可。
- .idea/
- migrations/
新建gitee仓库,这个页面填写 仓库名称,选择 私有 即可。
创建完成页面。这里要记住你的git remote add origin 红框命令。
找到想要上传的文件夹,将.gitignore文件放在主目录中,鼠标右键选择Open Git Bash here,打开git页面。
打开的git页面
第一次打开git页面输入,在git页面输入以下命令,如果已经打开无需再次输入。
- git config --global user.name "XXXX" # 只需要输入一次,之前输入过不用再次输入
-
- git config --global user.email "邮箱.com" # 只需要输入一次,之前输入过不用再次输入
没有报错再次输入
- git init
-
- git remote add origin https://gitee.com/XXXX/430.git # 此代码是你仓库的http地址
如果报错 error: remote origin already exists. 输入
git remote rm origin
上面的步骤操作完成后,以后只需要输入以下命令就可将代码上传至仓库。
期间可能会让输入gitee仓库账号和密码。
- git add .
-
- git commit -m 'init' # 如果更新代码修改git commit -m '修改内容'
-
- git push origin master
更新代码只需要修改 git commit -m '修改内容'
如果有修改.gitignore,只需要多执行一行git rm -r --cached .
- git rm -r --cached . #清除缓存
-
- git add .
-
- git commit -m '删除测试'
-
- git push origin master
#是注释,不要把#号及后面内容输入到git页面,会出错
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。