使用原始创建/修改时间戳检出旧文件 [英] Checking out old file WITH original create/modified timestamps

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

问题描述

有什么方法可以知道或获取原始创建/修改的时间戳吗?感谢。

解决方案

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

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

  IFS =

用于$(git ls - 文件)

TIME = $(git log --pretty = format:%cd -n 1 --date = iso - $ FILE)
TIME = $(date -j -f'%Y-%m-%d%H:%M:%S%z'$ TIME+%Y%m%d%H%M%S)
touch -m -t$ TIME$ FILE
完成


Is there any way to know or get the original create/modified timestamps? Thanks.

解决方案

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 -- "$FILE")
    TIME=$(date -j -f '%Y-%m-%d %H:%M:%S %z' "$TIME" +%Y%m%d%H%M.%S)
    touch -m -t "$TIME" "$FILE"
done

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

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