git use commit times for timestamps

来源:互联网 发布:万网阿里云 编辑:程序博客网 时间:2024/04/30 06:54

轉載自http://stackoverflow.com/questions/1964470/whats-the-equivalent-of-use-commit-times-for-git

 

If, however you really want to use commit times for timestamps when checking out then try using this script and place it (as executable) in the file $GIT_DIR/.git/hooks/post-checkout:

#!/bin/sh -eOS=${OS:-`uname`}old_rev="$1"new_rev="$2"get_file_rev() {    git rev-list -n 1 "$new_rev" "$1"}if   [ "$OS" = 'Linux' ]then    update_file_timestamp() {        file_time=`git show --pretty=format:%ai --abbrev-commit "$(get_file_rev "$1")" | head -n 1`        touch -d "$file_time" "$1"    }elif [ "$OS" = 'FreeBSD' ]then    update_file_timestamp() {        file_time=`date -r "$(git show --pretty=format:%at --abbrev-commit "$(get_file_rev "$1")" | head -n 1)" '+%Y%m%d%H%M.%S'`        touch -h -t "$file_time" "$1"    }else    echo "timestamp changing not implemented" >&2    exit 1fiIFS=`printf '\t\n\t'`for file in `git ls-files`do    update_file_timestamp "$file"done


0 0
原创粉丝点击