IDEA编写python代码上传仓库.gitignore忽略文件不起作用

语言框架:python-flask

IDE:JetBrains IDEA

工具:git

系统:win11

问题:

       python-flask在往gitee仓库上传代码的时候,官网下载的.gitignore文件不起作用,根本删除不了不想要的文件。

        以python-flask项目举例。

1.下载.gitignore

        打开下方网址: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/

 2.创建gitee仓库

        新建gitee仓库,这个页面填写 仓库名称,选择 私有 即可。

创建完成页面。这里要记住你的git remote add origin 红框命令。

3.下载打开git

找到想要上传的文件夹,将.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 '修改内容' 

4.修改.gitignore文件

如果有修改.gitignore,只需要多执行一行git rm -r --cached .

git rm -r --cached .       #清除缓存   

git add .

git commit -m '删除测试'

git push origin master

总结:

#是注释,不要把#号及后面内容输入到git页面,会出错

  • 11
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值