1

I try to work using Git.

I have experience many conflicts problems and try to understand better Git in order to implement a workflow that should prevent if possible conflicts (even if it is not always possible)

I have origin/master branch (=dev branch) on my Gitlab remote repository and the corresponding master in my local repository.

I have defined a backlog with differents isues.

I decide to work on issue #1 so I pull origin/master to be up-to-date in my local master and create a local branch name feature/1.

I work on this feature/1 branch and commit yesterday.

I did not finish to work on this issue but when I finish, but to complete workflow, I will push this feature/1 on Gitlab and make a merge request in order to merge with origin/mater. After that, I pull origin/master, suppress my local feature/1 branch and create a new feature/2 branch.

This morning, I checkout on my local master to verify I am still up-to-date with origin/master and it is the case except that git mentionned that 3 files have been modified:

On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    myapp/__pycache__/settings.cpython-37.pyc
        deleted:    myapp/__pycache__/urls.cpython-37.pyc
        deleted:    myapp/__pycache__/views.cpython-37.pyc

I understand pychache files are pre-compiled code to speed code execution.

But I did not understand: I have not worked on my local master and pycache is mentionned in my .gitignore files store at the root.

So why this files are mentionned? If I commit, I will ahead of one commit with origin/master and will have to push?

What is wrong with my workflow?

bignose
  • 30,281
  • 14
  • 77
  • 110
SLATER
  • 613
  • 9
  • 31
  • Can you sharr your `.gitignore` file where you aim to ignore these? – Willem Van Onsem Dec 04 '19 at 09:08
  • should I do git restore --staged to get back my local master = origin/master? – SLATER Dec 04 '19 at 11:09
  • Does this answer your question? [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – phd Dec 04 '19 at 11:34

2 Answers2

1

Those files exist in the repository (possibly from a time or branch where you didn't have a .gitignore), but have been deleted on your local box.

You may want to make a commit that cleans them (all) out from your master or whatever, say with something like

git ls-files '*.pyc' | xargs git rm -f

and then commit the changes.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • I delete them doing git rm --cached myapp/__pycache__/settings.cpython-37.pyc etc... thinking I could switch to my feature/1 branch without commit but I can't switch branch without commit – SLATER Dec 04 '19 at 10:57
  • I never use | and xargs... if I understand this command line, it select all files with.pyc extension ; this selection is passed through the pipe and run a git rm forced on all selected files... if so, it seems to be the same I do... – SLATER Dec 04 '19 at 11:04
0

.gitignore

__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# 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/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/
.vscode
# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.DS_Store
*.sqlite3
media/
*.pyc
*.db
*.pid


# Dossier généré par l'IDE Pycharm
.idea

# No migrations
**/migrations/**
!**/migrations/**
!**/migrations/__init__.py

# VS Code
.vscode


SLATER
  • 613
  • 9
  • 31