Skip to content

Instantly share code, notes, and snippets.

@talbright
Created February 15, 2015 18:20
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 talbright/ae923c8961d38e421144 to your computer and use it in GitHub Desktop.
Save talbright/ae923c8961d38e421144 to your computer and use it in GitHub Desktop.
Sets file mtimes to latest git commit timestamp
# Ensures mtimes are consistent with the git commit to utilize ADD caching
# Re-written from https://github.com/docker-library/official-images/blob/1dd9118804a06fef308e613cdbabe44bf0529043/bashbrew/git-set-mtimes
# This version is more platform compatible (assuming you have ruby), works on os x and *nix
git_set_mtimes() {
pushd $1
IFS=$'\n'
files=( $({ git ls-files | xargs dirname | sort -u && git ls-files; } | sort -r) )
unset IFS
for f in "${files[@]}"; do
stamp="$(git --no-pager log -1 --format='format:%ai' -- "$f")"
tstamp=$(echo $stamp | ruby -r 'date' -ne 'puts DateTime.parse($_).strftime("%Y%m%d%H%M.%S")')
touch -h -t "$tstamp" "$f"
done
popd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment