Skip to content

Instantly share code, notes, and snippets.

@ryanemmm
Created October 23, 2015 18:03
Show Gist options
  • Save ryanemmm/388a7fc3ea3d33f72e04 to your computer and use it in GitHub Desktop.
Save ryanemmm/388a7fc3ea3d33f72e04 to your computer and use it in GitHub Desktop.
# from: http://blog.pivotal.io/labs/labs/a-simple-way-to-detect-unused-files-in-a-project-using-git
# `git ls-files` -> get a list of files from a directory
# `git grep` + loop -> check for reference to file in repo
# list or remove the file
# dry run: just list the unused files
for FILE in $(git ls-files ./img); do
git grep $(basename "$FILE") > /dev/null || echo "would remove $FILE"
done
# for real: git rm the file
for FILE in $(git ls-files ./img); do
git grep $(basename "$FILE") > /dev/null || git rm "$FILE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment