Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nicolasmendoza/f4f43de04ccdce167604 to your computer and use it in GitHub Desktop.
Save nicolasmendoza/f4f43de04ccdce167604 to your computer and use it in GitHub Desktop.
39 de 1.327 Be careful deleting files around gi
Working in a Python project, it's common to have a clean-up step that deletes all the .pyc files, like this:
$ find . -name '*.pyc' -delete
This works great, but there's a slight chance of a problem: Git records information about branches in files within the .git directory. These files have the same name as the branch.
Try this:
$ git checkout -b cleaup-all-.pyc
This makes a branch called "cleanup-all-.pyc". After making a commit, I will have files named .git/refs/heads/cleanup-all-.pyc and logs/refs/heads/cleanup-all-.pyc. Now if I run my find command, it will delete those files inside the .git directory, and my branch will be lost.
One way to fix it is to tell find not to delete the file if it's found in the .git directory:
$ find . -name '*.pyc' -not -path './.git/*' -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment