git-clean with GitPython - python

Is there any way to do something like git clean -d -x -f using GitPython?
I need to reset working directories and want to get rid of all unversioned files without deleting the whole folder (except for .git) and checking out again.

You can work around by using the git command directly, from gitpython
git = repo.git
git.clean('-xdf')

Related

My interpreter has been deleted by command 'git clean -d -f'

My python interpreter setting been deleted by this git clean -d -f so now do i have to reinstall all package requirements?. Is there any way i can undo this.
I was trying to remove _ _ pychache _ _ files. but by mistake typed this git clean -d -f command.
if I had to install all packages again then i would be in big trouble cause of high chances of mismatch module version
If the file was private, meaning not added to the index through git add, and not committed, then double-check your editor/IDE: it might still have a local history for that file.
If not, then you need to use a file recovery utility, as detailed in "Can I restore deleted files (undo a git clean -fdx)?".
It is best to have an alias for git clean, in order to delete the (.gitignore'd) __pycache__ while keeping the (.gitignore'd) .iml/.idea project setting files you want to keep during a clean (even an inadvertent one)

How to do git checkout -q --archive with Python?

I'm trying build an code in python using git.Is there any command to do git checkout -q --dir on python?
Now I'm using Python 3 and git package to do this, but i don't found command to this.
I'm running a git pull before (and the command exists), there is a file that can not be deleted and only the git checkout can restore it. Anyone know if this is possible?

How to ignore generated cpp files (from swig/python) in Coverity Scan?

I've got a C++ project with Python bindings generated by SWIG. I get a generated file python/libproj_wrap.cpp from SWIG. This file is listed in .gitignore.
I'm running Coverity Scan through Travis. It seems like Coverity Scan tries to run git blame on this, which fails:
fatal: no such path 'python/libproj_wrap.cpp' in HEAD
[WARNING] An error occurred while executing command at '/home/travis/build/unhammer/proj/python':
COMMAND: '/usr/bin/git blame -p proj_wrap.cpp' failed. Error code 128. Proceeding...
and I get no scan results. Is there a way to tell Coverity Scan to ignore .gitignore'd stuff, or should I just run the scan on a build configured without SWIG bindings?
That would happen if python/libproj_wrap.cpp was tracked before being added to the .gitignore.
Just to be sure, try and untrack it:
git rm --cached python/libproj_wrap.cpp
git commit -m "untrack python/libproj_wrap.cpp"
git push
And see if Travis is still trying a git blame on that file.

Unable to git add env/bin directory after creating virtualenv

I am really new to Python and the virtualenv needed to set up a project. I dont know whether the directories generated by virtualenv should be gitignored or staged and committed.
I narrowed it down to the myproject/env/bin directory that doesn't seem to want to be staged. After running git add env/bin once I get.
[1] 16599 killed git add env/bin
And then after running the same git add env/bin again I get.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'....
There are no other git process running. Thanks for your help!
After looking through a few other Python/Django repositories on Github, I see that most have add the env/bin, env/include and env/lib directories (generated by virtualenv) to their .gitignore file. I'll take this at face value and move on til I have a better understanding of virtualenv. Thanks!

Git Ignore for metadata and other settings?

I'm having a problem with my .gitignore, since it seems to be ignoring the file extensions in there. Every time I change any file I end up with hundreds of other files. I've looked at previous posts on here to deal with the problem, and I copied what I have in my .gitignore from a git repository: https://github.com/github/gitignore/blob/master/Global/Eclipse.gitignore
but that doesn't seem to be working. I've restarted Eclipse, refreshed my git repo and nothing is happening.
Any advice?
It seems those files have been added to the git repository already.
Are those "not staged files" or "untracked files"? In case of former, you remove files from repository using following commend.
git rm --cached

Categories