git status
时发现有很多 .pyc 的没有被 add
bash
(env) username:~/path/to/project$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: xxx.py
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: __pycache__/main.cpython-38.pyc
modified: ldm/__pycache__/util.cpython-38.pyc
modified: ldm/data/__pycache__/__init__.cpython-38.pyc
modified: ldm/data/__pycache__/base.cpython-38.pyc
modified: ldm/data/__pycache__/list_fonts.cpython-38.pyc
modified: ldm/data/__pycache__/rasterizer.cpython-38.pyc
modified: ldm/models/__pycache__/autoencoder.cpython-38.pyc
modified: ldm/models/diffusion/__pycache__/__init__.cpython-38.pyc
modified: ldm/models/diffusion/__pycache__/ddim.cpython-38.pyc
modified: ldm/models/diffusion/__pycache__/ddpm.cpython-38.pyc
modified: ldm/models/diffusion/__pycache__/plms.cpython-38.pyc
modified: ldm/modules/__pycache__/attention.cpython-38.pyc
modified: ldm/modules/__pycache__/discriminator.cpython-38.pyc
modified: ldm/modules/__pycache__/ema.cpython-38.pyc
modified: ldm/modules/__pycache__/x_transformer.cpython-38.pyc
modified: ldm/modules/diffusionmodules/__pycache__/__init__.cpython-38.pyc
modified: ldm/modules/diffusionmodules/__pycache__/model.cpython-38.pyc
modified: ldm/modules/diffusionmodules/__pycache__/openaimodel.cpython-38.pyc
modified: ldm/modules/diffusionmodules/__pycache__/util.cpython-38.pyc
modified: ldm/modules/distributions/__pycache__/__init__.cpython-38.pyc
modified: ldm/modules/distributions/__pycache__/distributions.cpython-38.pyc
modified: ldm/modules/encoders/__pycache__/__init__.cpython-38.pyc
modified: ldm/modules/encoders/__pycache__/modules.cpython-38.pyc
- .pyc 文件是什么?
Python 编译的字节码文件(.pyc 文件)**通常是 Python 解释器将 Python 源代码编译成的字节码文件。**当运行 Python 程序时,解释器会首先尝试加载这些 .pyc 文件,以加快程序的启动速度。
- 这些 .pyc 文件通常是由 Python 解释器根据对应的 Python 源代码生成的,它们会在 Python 源代码发生变化时自动更新。
- 但有时候,这些 .pyc 文件可能会被修改,例如在一些编辑器或 IDE 中保存文件时可能会触发 Python 解释器重新生成这些文件。(本文是在 vs code 中运行过项目的 python 代码)
- 是否有必要同步到 GitHub 远程仓库?
没有必要。
- 通常情况下,这些 .pyc 文件的修改不会影响到项目或者安装的包的行为,因为它们只是编译后的字节码文件,而不是源代码文件。
- 因此,如果不希望将这些 .pyc 文件纳入到 Git 版本控制中,可以考虑将它们加入到 .gitignore 文件中,以免每次提交时都会看到它们的修改。