Skip to content

Instantly share code, notes, and snippets.

@mikoim
Created October 5, 2017 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikoim/5a6e80443b7b5fb1d2a98c488bc41ce9 to your computer and use it in GitHub Desktop.
Save mikoim/5a6e80443b7b5fb1d2a98c488bc41ce9 to your computer and use it in GitHub Desktop.
Optimize all png files in history of repository with "git filter-branch" command
#!/bin/sh
FILENAME="$1"
HASH=$(md5sum "${FILENAME}")
HIT=$(grep -c "${HASH}" /tmp/hash.txt)
echo "${FILENAME}"
if [ "${HIT}" -eq 0 ];then
optipng -o7 -clobber "${FILENAME}"
HASH=$(md5sum "${FILENAME}")
echo "${HASH}" >> /tmp/hash.txt
else
echo "SKIP"
fi
#!/bin/sh
CMD="find . -iname '*\.png' -type f -print0 | xargs -0 -L 1 -P 4 --no-run-if-empty /tmp/optimize.sh"
git filter-branch --prune-empty --tree-filter "${CMD}" --force HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment