git-set-mtimes 412 B

12345678910111213141516
  1. #!/bin/bash
  2. set -e
  3. IFS=$'\n'
  4. files=( $({ git ls-files | xargs -n1 dirname | sort -u && git ls-files; } | sort -r) )
  5. unset IFS
  6. for f in "${files[@]}"; do
  7. if [ ! -e "$f" ]; then
  8. # don't try touching files that don't exist
  9. continue
  10. fi
  11. stamp="$(git --no-pager log -1 --format='format:%ai' -- "$f")"
  12. touchFormat="$(date --date="$stamp" +'%Y%m%d%H%M.%S')"
  13. touch --no-dereference -t "$touchFormat" "$f"
  14. done