Automatically remove *.pyc files and otherwise-empty directories when I check out a new branch

后端 未结 4 1443
没有蜡笔的小新
没有蜡笔的小新 2020-12-12 16:31

So here\'s an interesting situation when using git and python, and I\'m sure it happens for other situations as well.

Let\'s say I make a git repo with a folder /foo

4条回答
  •  旧巷少年郎
    2020-12-12 17:02

    Just copying and updating a good solution by Apreche that was buried in the comments:

    Save this shell script to the file /path/to/repo/.git/hooks/post-checkout, and make it executable.

    #! /bin/sh
    
    # Start from the repository root.
    cd ./$(git rev-parse --show-cdup)
    
    # Delete .pyc files and empty directories.
    find . -name "*.pyc" -delete
    find . -type d -empty -delete
    

提交回复
热议问题