Skip to content

Instantly share code, notes, and snippets.

@demofly
Last active November 3, 2016 16:00
Show Gist options
  • Save demofly/acf236b9e7ba4cc82fd89e7489147142 to your computer and use it in GitHub Desktop.
Save demofly/acf236b9e7ba4cc82fd89e7489147142 to your computer and use it in GitHub Desktop.
How to recover mtime dates from git log: recover-mtime-dates-from-git.sh
#!/bin/bash
git ls-tree `git rev-parse HEAD` -rt --full-tree | sed -r 's#\w+ \w+ \w+\s+##' | while read FILE
do
TIME=$(git log --pretty=format:%cd -n 1 --date=iso "$FILE" 2>/dev/null)
test -z "$TIME" && continue
# TIME2=`echo $TIME | sed 's/-//g;s/ //;s/://;s/:/\./;s/ .*//'`
echo "$FILE"
# echo -n " - old mtime: "
# date -r "$FILE" -Ins
# echo " - new mtime: $TIME2"
## When you want to recover back the timestamps:
touch -h -m -d "$TIME" "$FILE"
# touch -h -m -t $TIME2 "$FILE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment