Skip to content

Instantly share code, notes, and snippets.

@cedricbdev
Last active September 21, 2020 13:40
Show Gist options
  • Save cedricbdev/a81bd2ca73a90f7f7ae512e45c7ba1e7 to your computer and use it in GitHub Desktop.
Save cedricbdev/a81bd2ca73a90f7f7ae512e45c7ba1e7 to your computer and use it in GitHub Desktop.
A simple way to detect unused files in a project using git
#!/bin/sh
for FILE in $(git ls-files ./img); do
# echo files that should be removed
# git grep $(basename "$FILE") > /dev/null || echo "would remove $FILE"
# remove files that should be removed
git grep $(basename "$FILE") > /dev/null || git rm "$FILE"
done
# credit: https://tanzu.vmware.com/content/blog/a-simple-way-to-detect-unused-files-in-a-project-using-git
# Do not forget to add execution rights to the file: > chmod +x remove-images.sh
# Run the script with: > ./remove-images.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment