检出带有原始创建/修改时间戳的旧文件 [英] Checking out old files WITH original create/modified timestamps

查看:25
本文介绍了检出带有原始创建/修改时间戳的旧文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法知道或获取原始的创建/修改时间戳?

解决方案

我相信 Git 数据库中记录的唯一时间戳是作者和提交时间戳.我没有看到 Git 修改文件时间戳以匹配最近提交的选项,并且这不是默认行为是有道理的(因为如果是,Makefiles 将无法正常工作).

您可以编写一个脚本,将文件的修改日期设置为最近一次提交的时间.它可能看起来像这样:

IFS=""对于 $(git ls-files) 中的文件做TIME=$(git log --pretty=format:%cd -n 1 --date=iso --date-order -- "$FILE")# 选择1个版本.# 这是用于 BSD 日期(macOS、FreeBSD 等)#TIME=$(date -j -f '%Y-%m-%d %H:%M:%S %z' "$TIME" +%Y%m%d%H%M.%S)# 这相当于 GNU coreutils date (Linux)TIME=$(date --date=$TIME"+%Y%m%d%H%M.%S)touch -m -t "$TIME";$文件"完毕

Is there a way to know or get the original create/modified timestamps?

解决方案

I believe that the only timestamps recorded in the Git database are the author and commit timestamps. I don't see an option for Git to modify the file's timestamp to match the most recent commit, and it makes sense that this wouldn't be the default behavior (because if it were, Makefiles wouldn't work correctly).

You could write a script to set the modification date of your files to the the time of the most recent commit. It might look something like this:

IFS="
"
for FILE in $(git ls-files)
do
    TIME=$(git log --pretty=format:%cd -n 1 --date=iso --date-order -- "$FILE")

    # Choose 1 version.
    # This is for BSD date (macOS, FreeBSD, etc)
    #TIME=$(date -j -f '%Y-%m-%d %H:%M:%S %z' "$TIME" +%Y%m%d%H%M.%S)

    # And this is the equivalent for GNU coreutils date (Linux)
    TIME=$(date --date="$TIME" +%Y%m%d%H%M.%S)

    touch -m -t "$TIME" "$FILE"
done

这篇关于检出带有原始创建/修改时间戳的旧文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆