0

I've been creating a Django app and I have a question about .pyc. I don't know exactly when, but I believe when I created a branch and moved into the branch, I always had a problem about .pyc. Three .pyc files always emerge to branch areas on VSCode. enter image description here

I want to even delete the three files, but I don't think it's the best way to solve this. Or maybe I can't delete them for another reason.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Sana
  • 317
  • 3
  • 17
  • 2
    you can write a `.gitignore` file to ignore this files outside the SCM,here is a example on python ignore https://github.com/github/gitignore/blob/master/Python.gitignore – nay Aug 01 '21 at 08:24
  • 2
    Why do you *want* to delete them? They contain the bytecode that Python executes. You can switch off the creation of `.pyc` files by setting the environment variable PYTHONDONTWRITEBYTECODE. But that will slow down program startup because the interpreter will then have to convert your source (and all imports) to bytecode afresh every time you run it. – BoarGules Aug 01 '21 at 08:30
  • [The answer is in this link, check it out](https://stackoverflow.com/questions/936249/how-to-stop-tracking-and-ignore-changes-to-a-file-in-git) – Nicolas Aug 17 '21 at 07:36

2 Answers2

1

You can put these files in .gitignore. Add whatever you don't want to push to git

*.egg
*.egg-info
*.bv
*.pyc
build
__pycache__
eggs
0

First add those three file names or provide extension like this *.xyz inside your .gitignore file and than run this command git rm --cached . to remove cached files and than push it to your branch

'.' represent all files in current directory if you want to remove chache of perticular file than add file names like this git rm --cached file1 file2

Ankit Tiwari
  • 4,438
  • 4
  • 14
  • 41