简体   繁体   中英

Removed .py files, compiled .pyc files and git - how to?

I have removed some files ( a.py and b.py ) from project and committed my changes. My teammate pulled changes and program exited with errors.

After some research we have found problem: Git removed a.py and b.py files, but compiled .pyc files remained and caused problems - program used old sources and get an errors.

.pyc files ignored in .gitignore .

What is the best solution to solve such problem?

UPDATE: I know how to ignore files - question not about it. Question is how to avoid situations described above?

Python only recompiles the .pyc files when the .py files are newer. This can be a problem in projects with multiple users if your version control uses the date of the original edit rather than the date when changes were last pulled.

Simply put, if you have multiple developers on a project be prepared to occasionally delete .pyc files manually:

find . -name "*.pyc" -delete

will do the job on Linux.

As pointed out in the comments you can include that in post-merge or post-checkout hooks so it runs automatically.

You will simply have to go through and delete the .pyc files. The python interpreter is such that the .pyc files are always used unless the .py files are newer (in which case it recompiles the .pyc file).

A good solution is to include a cleaning step in your workflow that removes all .pyc files before running the program:

find . -name "*.pyc" -delete

Add this post-checkout script in .git/hooks/post-checkout:

git diff --name-status $1 $2 -- '*.py' | grep ^D | sed 's/py$/pyc/' | xargs rm -vf

Translated: Take .py files that were deleted by the checkout, and remove (delete) their corresponding pyc files.

try this:

git rm <filename>

git rm documentation

git rm -f *.pyc

The solution is to clean the working dir and reset it to a prestine state prior to every usage or at least after each update of the checked-out revision.

Try something like (and be aware that it WILL delete files which are not tracked):

git clean -f

See also: How to remove local (untracked) files from the current Git working tree?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM