#!/bin/sh export PATH=/usr/local/bin:/usr/bin:/bin # cd to the root of the project directory (assume one dir up from GIT_DIR) cd $GIT_DIR/.. unset GIT_DIR # Set up some temporary files and a trap to delete them oldlist=$(tempfile) newlist=$(tempfile) removelist=$(tempfile) trap "rm -f $oldlist $newlist $removelist" 0 1 2 3 15 # Get list of files from the current index git-ls-files | sort -r > $oldlist # Checkout the index to the working directory git-checkout-script -f # Get list of files from the current (new) index git-ls-files | sort -r > $newlist # Use diff to determine which files to remove from the working copy diff -u $oldlist $newlist | tail -n +4 | sed -n 's/^-//p' > $removelist cat $removelist | xargs -rl rm -f cat $removelist | xargs -rl dirname | xargs -rl rmdir -p --ignore-fail-on-non-empty