Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to set the times of a working copy to the last commit time.
#!/bin/bash
# Usage: git settimes [-v]
SAVE_IFS=$IFS
VERBOSE="False"
if [[ $1 == "-v" ]]; then
VERBOSE="True"
fi
IFS=$(echo -en "\n\b")
for FILE in $(git ls-files)
do
if [[ $VERBOSE == "True" ]]; then
echo Updating timestamp: $FILE
fi
TIME=$(git log --pretty=format:%cd -n 1 --date=iso -- "$FILE")
#TIME=$(date -f '%Y-%m-%d %H:%M:%S %z' "$TIME" +%Y%m%d%H%M.%S)
TIME=$(date -d "$TIME" +%Y%m%d%H%M.%S)
touch -m -t $TIME "$FILE"
done
IFS=$SAVE_IFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.