Skip to content

Instantly share code, notes, and snippets.

@minyoad
Last active August 24, 2020 08:32
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 minyoad/b27fb53af3930d0093b94b823f0c2292 to your computer and use it in GitHub Desktop.
Save minyoad/b27fb53af3930d0093b94b823f0c2292 to your computer and use it in GitHub Desktop.
git hooks pre-commit to automatic update *.js *.css version
#!/bin/bash
###
## change js and css file version by append ?v111111
##
## usage: copy to .git/hooks/pre-commit
## chmod a+x .git/hooks/pre-commit
#
##
modified_files=$(git diff --cached --name-only)
#echo $modified_files
for f in $modified_files
do
#echo $f
ext="${f##*.}"
fname=`basename $f`
if [ -e "$f" ] && ([[ $ext == css ]] || [[ $ext == js ]] ); then
include_files=`grep src -r -e "$fname" |awk -F: '{print $1}' |uniq`
for f2 in $include_files
do
ver=`stat -c %Y $f2`
sed -i "s/$fname.*\"/$fname\?v$ver\"/g" $f2
git add $f2
done
git add $f
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment