i\'m working on a big python project, and i\'m really sick if .pyc and *~ files. I\'d like to remove them. I\'ve seen that the -X
flag of git clean would remove
If you have commited the pyc's and so on already, do the following:
Add *.pyc, *~ and local_settings.py to the .gitignore. Then do in your git repository:
find . -name '*.pyc' | xargs rm
find . -name '*~' | xargs rm
then do:
git commit -am "get rif of them"
now they shouldn't bother you anymore
The difference is the capital X
you're using. Use a small x
instead of the capital one. Like in: git clean -x
.
git clean -x -n -e local_settings.py # Shows what would remove (-n flag)
git clean -x -f -e local_settings.py # Removes it (note the -f flag)
From the git documentation:
-x Don't use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with -e options. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build. -X Remove only files ignored by git. This may be useful to rebuild everything from scratch, but keep manually created files.
If you're running Python 2.6+ just set the environment variable, PYTHONDONTWRITEBYTECODE
, to true
. You can just add the following to something like .profile
or .bashrc
to disable it entirely for your profile:
export PYTHONDONTWRITEBYTECODE=true
Or, if you just want to do that for a particular project you're working, you'll need to run the above in your shell each time (or in one of your virtualenv init scripts if you're using virtualenv and virtualenvwrapper), or you can simply pass the -B
parameter when you call python
, e.g.
python -B manage.py runserver
I put local files that fall into this category in .git/info/exclude (e.g. my IDE project files). They you can do a clean like this:
git ls-files --others --exclude-from=.git/info/exclude -z | \
xargs -0 --no-run-if-empty rm --verbose
Where:
You could create an alias, e.g.:
git config --global alias.myclean '!git ls-files --others --exclude-from=.git/info/exclude -z | xargs -0 --no-run-if-empty rm --verbose --interactive'
The --interactive means you have to do git myclean -f to force the deletion.
Reference: http://git-scm.com/docs/git-ls-files (plus the first line of the default .git/info/exclude)
git clean -X -n --exclude="!local_settings.py"
works. I discovered this when I googled and got this page.