当前位置:   article > 正文

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

python ignore .idea

语言框架: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,放至要上传仓库的代码的主目录。

  1. # 文件名称 .gitignore
  2. # Byte-compiled / optimized / DLL files
  3. __pycache__/
  4. *.py[cod]
  5. *$py.class
  6. # C extensions
  7. *.so
  8. # Distribution / packaging
  9. .Python
  10. build/
  11. develop-eggs/
  12. dist/
  13. downloads/
  14. eggs/
  15. .eggs/
  16. lib/
  17. lib64/
  18. parts/
  19. sdist/
  20. var/
  21. wheels/
  22. share/python-wheels/
  23. *.egg-info/
  24. .installed.cfg
  25. *.egg
  26. MANIFEST
  27. # PyInstaller
  28. # Usually these files are written by a python script from a template
  29. # before PyInstaller builds the exe, so as to inject date/other infos into it.
  30. *.manifest
  31. *.spec
  32. # Installer logs
  33. pip-log.txt
  34. pip-delete-this-directory.txt
  35. # Unit test / coverage reports
  36. htmlcov/
  37. .tox/
  38. .nox/
  39. .coverage
  40. .coverage.*
  41. .cache
  42. nosetests.xml
  43. coverage.xml
  44. *.cover
  45. *.py,cover
  46. .hypothesis/
  47. .pytest_cache/
  48. cover/
  49. # Translations
  50. *.mo
  51. *.pot
  52. # Django stuff:
  53. *.log
  54. local_settings.py
  55. db.sqlite3
  56. db.sqlite3-journal
  57. # Flask stuff:
  58. instance/
  59. .webassets-cache
  60. # Scrapy stuff:
  61. .scrapy
  62. # Sphinx documentation
  63. docs/_build/
  64. # PyBuilder
  65. .pybuilder/
  66. target/
  67. # Jupyter Notebook
  68. .ipynb_checkpoints
  69. # IPython
  70. profile_default/
  71. ipython_config.py
  72. # pyenv
  73. # For a library or package, you might want to ignore these files since the code is
  74. # intended to run in multiple environments; otherwise, check them in:
  75. # .python-version
  76. # pipenv
  77. # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
  78. # However, in case of collaboration, if having platform-specific dependencies or dependencies
  79. # having no cross-platform support, pipenv may install dependencies that don't work, or not
  80. # install all needed dependencies.
  81. #Pipfile.lock
  82. # poetry
  83. # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
  84. # This is especially recommended for binary packages to ensure reproducibility, and is more
  85. # commonly ignored for libraries.
  86. # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
  87. #poetry.lock
  88. # pdm
  89. # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
  90. #pdm.lock
  91. # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
  92. # in version control.
  93. # https://pdm.fming.dev/#use-with-ide
  94. .pdm.toml
  95. # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
  96. __pypackages__/
  97. # Celery stuff
  98. celerybeat-schedule
  99. celerybeat.pid
  100. # SageMath parsed files
  101. *.sage.py
  102. # Environments
  103. .env
  104. .venv
  105. env/
  106. venv/
  107. ENV/
  108. env.bak/
  109. venv.bak/
  110. # Spyder project settings
  111. .spyderproject
  112. .spyproject
  113. # Rope project settings
  114. .ropeproject
  115. # mkdocs documentation
  116. /site
  117. # mypy
  118. .mypy_cache/
  119. .dmypy.json
  120. dmypy.json
  121. # Pyre type checker
  122. .pyre/
  123. # pytype static type analyzer
  124. .pytype/
  125. # Cython debug symbols
  126. cython_debug/
  127. # PyCharm
  128. # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
  129. # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
  130. # and can be added to the global gitignore or merged into this file. For a more nuclear
  131. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
  132. .idea/
  133. migrations/

        注意:以上代码是我修改过的,我修改了最后两行。

        .gitignore,放至要上传仓库的代码的主目录。

        官网下载的gitignore文件删除不掉JetBrains IDEA编译器产生的.idea 和migrations文件夹。
        在.gitignore文件中添加以下两行即可,也可以其他删除的文件或文件夹,直接复制我的代码即可。

  1. .idea/
  2. migrations/

 2.创建gitee仓库

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

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

3.下载打开git

找到想要上传的文件夹,将.gitignore文件放在主目录中,鼠标右键选择Open Git Bash here,打开git页面。

打开的git页面

第一次打开git页面输入,在git页面输入以下命令,如果已经打开无需再次输入。

  1. git config --global user.name "XXXX" # 只需要输入一次,之前输入过不用再次输入
  2. git config --global user.email "邮箱.com" # 只需要输入一次,之前输入过不用再次输入

没有报错再次输入

  1. git init
  2. git remote add origin https://gitee.com/XXXX/430.git # 此代码是你仓库的http地址

如果报错 error: remote origin already exists. 输入

git remote rm origin

上面的步骤操作完成后,以后只需要输入以下命令就可将代码上传至仓库。

期间可能会让输入gitee仓库账号和密码。

  1. git add .
  2. git commit -m 'init' # 如果更新代码修改git commit -m '修改内容'
  3. git push origin master

更新代码只需要修改 git commit -m '修改内容' 

4.修改.gitignore文件

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

  1. git rm -r --cached . #清除缓存
  2. git add .
  3. git commit -m '删除测试'
  4. git push origin master

总结:

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/711660
推荐阅读
相关标签
  

闽ICP备14008679号