Created
May 5, 2015 18:06
-
-
Save nicolasmendoza/f4f43de04ccdce167604 to your computer and use it in GitHub Desktop.
39 de 1.327 Be careful deleting files around gi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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