So, an interesting situation when using git and python, and I am sure that this happens for other situations as well.
Let's say I create a git repository with the / foo / folder. In this folder I put /foo/program.py. I run program.py and program.pyc. I have * .pyc in a .gitignore file, so git does not track it.
Now let me say that I am doing another branch, dev. In this dev branch, I completely delete the / foo / folder.
Now I switch back to the main branch and / foo / appears again. I run program.py and the program.pyc file appears again. All right.
I am going back to my dev branch. The directory / foo / should disappear. It exists only in the master branches, and not in the dev branches. However, it still exists. What for? Since the ignored program.pyc file prevents the folder from being deleted when switching branches.
The solution to this problem is to recursively delete all * .pyc files before switching branches. I can easily do this with this command.
find . -name "*.pyc" -exec rm '{}' ';'
The problem is that the annoyance needs to be remembered in order to do this almost every time I change branches. I could make an alias for this command, but then I still have to remember to enter it every time I change branches. I could also make an alias for git-branch, but nothing good. The git branch command does things other than change branch changes, and I don't want to delete all pyc files every time I use them. Damn, Iβd even use it in disrepute, then what?
Is there a way to set a git hook that only executes when changing branches? Or is there some other way that all * .pyc files are deleted whenever I switch branches?
git python bash
Apreche 01 Oct '09 at 15:41 2009-10-01 15:41
source share