Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tdurand/fcb4ca25389f5adca7f1 to your computer and use it in GitHub Desktop.
Save tdurand/fcb4ca25389f5adca7f1 to your computer and use it in GitHub Desktop.
#!/bin/sh
OS=${OS:-`uname`}
if [ "$OS" = 'Linux' ]
then
update_file_timestamp() {
file_time=`git log --no-merges --format=%ai "$1" | head -n 1`
echo "change timestamp file $file_time $1"
touch -d "$file_time" "$1"
}
elif [ "$OS" = 'FreeBSD' ] || [ "$OS" = 'Darwin' ];
then
update_file_timestamp() {
file_time=`date -r "$(git log --no-merges --format=%at "$1" | head -n 1)" '+%Y%m%d%H%M.%S'`
echo "change timestamp file $file_time $1"
touch -h -t "$file_time" "$1"
}
else
echo "timestamp changing not implemented" >&2
exit 1
fi
#List all the files of the git repository
for file in `git ls-tree -r --name-only HEAD`
do
if [ -f "$file" ]; then
#For each file update the file timestamp with the timestamp of the last commit on this file
update_file_timestamp "$file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment