Created
May 22, 2023 15:08
-
-
Save sloanlance/6ae879209ff488a26f786b240e06d3de to your computer and use it in GitHub Desktop.
Set timestamps of files in a cloned git repository to when they were last committed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -- | |
# Set timestamps of files in a cloned git repository to when they were last committed. | |
# Default: All git-controlled files in current directory, recursively | |
if [ ${#} = 0 ]; then | |
files="$(git ls-files -z | xargs -0 echo)" | |
else | |
files="${@}" | |
fi | |
for file in ${files}; do | |
time="$(git log --pretty=format:%cd -n 1 \ | |
--date=format:%Y%m%d%H%M.%S --date-order -- "${file}")" | |
if [ -z "${time}" ]; then | |
echo "ERROR: skipping '${file}' — no git log found" >&2 | |
continue | |
fi | |
echo "${file} → ${time}" | |
touch -m -t "${time}" "${file}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment