Skip to content

Instantly share code, notes, and snippets.

@tstone2077
Created February 12, 2015 16:52
Show Gist options
  • Save tstone2077/86529356dd120eb0e51f to your computer and use it in GitHub Desktop.
Save tstone2077/86529356dd120eb0e51f to your computer and use it in GitHub Desktop.
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