1、为什么git仓库没有保留文件修改时的时间戳?

 摘自:https://git.wiki.kernel.org/index.php/Git_FAQ#Why_isn.27t_Git_preserving_modification_time_on_files.3F

Why isn't Git preserving modification time on files?

Modification time on files is a feature that affects build tools.
Most build tools compare the timestamp of the source(s) with the timestamp of the derived file(s).

If the source is newer, then a rebuild takes place, otherwise nothing happens. This speeds up the build process a lot.

Now consider what would happen if you check out another branch, and modification times were preserved. We assume you already have a fully-built project.

If a source file on that other branch has a timestamp that is older than that of the corresponding derived file, the derived file will not be built even if it is different, because the build system only compares modification times.

At best, you'll get some kind of weird secondary error; but most likely everything will look fine at first, but you will not get the same result as you would have with a clean build. That situation is unhealthy since you really do not know what code you are executing and the source of the problem is hard to find.

You will end up always having to make a clean build when switching branches to make sure you are using the correct source.

(Git bisect is another Git procedure that checks out old and new revisions where you need a reliable rebuild.)
Git sets the current time as the timestamp on every file it modifies, but only those. The other files are left untouched, which means build tools will be able to depend on modification time and rebuild properly. If build rules change, that can cause a failure anyway, but that is a far less common problem than accidentally not rebuilding.

2、为什么git仓库仅仅保留change commit 的修改时间戳信息,而没有保留文件的时间戳信息?

摘自:https://stackoverflow.com/questions/2179722/checking-out-old-file-with-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 --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

git分支切换时的时间戳问题的更多相关文章

  1. 进行分支切换时,出现error的修复方法

    进行分支切换时,出现如此错误,导致无法正常切换:error: The following untracked working tree files would be overwritten by ch ...

  2. git 分支合并时如何忽略某个文件

    [转]git 分支合并时如何忽略某个文件 - 神奇的旋风 - 博客园 https://www.cnblogs.com/xuan52rock/p/13268872.html Git - git-merg ...

  3. git分支切换的一些问题

    关于git切换分支后该分支的修改会在另一个分支里面一起修改的问题 修改分支后导致稳定版的主分支里面的文件连带修改. 原因:切换分支前原分支没有提交,导致新建的文件或者文件夹,没有纳入版本管理,所以会被 ...

  4. git分支间切换注意点和bug分支的处理

    目录 备注: 知识点 记一次分支合并问题状况 从分支点开始,不同分支修改工作区的内容(不添加到暂存区和提交),切换分支,工作区的内容是一样的. 必须在提交或者暂存当前暂存区的状态后,再切换或合并分支 ...

  5. Git~分支真的很轻

    轻,让人觉得很爽 所有源代码管理工具都有管理分支的功能,git当然也不例外,而且git的分支是非常轻的,不像tfs,svn那样,复制一大堆代码,git只记录变化的内容,有本地分支与远程分支之分,原则上 ...

  6. idea中使用git进行clone、分支切换、pull、push等

    转:https://blog.csdn.net/xiaobai__lee/article/details/81081128 https://blog.csdn.net/geng31/article/d ...

  7. 【IntelliJ IDEA】在idea上操作 git分支合并【如何将远程swagger分支 合并到 远程 master分支上】【如何切换 本地分支】

    ============================================ 明确一点: 如果项目交给git管理了[如何将项目交给git管理:https://www.cnblogs.com ...

  8. Git分支,合并,切换分支的使用

    1.创建合并分支 在我们每次的提交,Git都把它们串成一条时间线,这条时间线就是一个分支.截止到目前,只有一条时间线,在Git里,这个分支叫主分支,即master分支.HEAD指针严格来说不是指向提交 ...

  9. 版本控制git之二 分支 切换分支 创建分支 合并 删除

      版本控制git之二 分支   有人把 Git 的分支模型称为它的`‘必杀技特性’',也正因为这一特性,使得 Git 从众多版本控制系统中脱颖而出. 为何 Git 的分支模型如此出众呢? Git 处 ...

随机推荐

  1. LisView控件

    用LisView控件在窗体中创建一个表,设置一个按钮,点击按钮, 将数据库中的表在这个控件中显示(LisView控件中表格式列名与数据库中一致) 首先使用控件将表的每一列创建好,加入一个按钮,如图,现 ...

  2. 使用yii\filters下的比如\PageCache需要在web.php里面的组件上配置'cache' => [ 'class' => 'yii\caching\FileCache', ],

    public function behaviors(){ /*需要在config文件下的web.php里面加上 'cache' => [ 'class' => 'yii\caching\F ...

  3. java NIO 文章

    http://tutorials.jenkov.com/java-nio/ 总结nio nio是非阻塞的,一个线程可以管多个Channel,每个channel可以处理bytebuffer 而no是阻塞 ...

  4. 游戏AI技术

    [Unity3D人工智能编程精粹] 1.运动层.决策层.战略层. 运动层.决策层包含的算法是针对单个角色的,战略层是针对小队乃至更大规模群体的. 导航和寻路是运行层的主要任务. 决策层决定角色下一时间 ...

  5. 我的一次rsync+inotify本地数据同步示例

    环境: web工作目录:/var/www/mydafuhao git仓库目录: /var/www/mydafuhao.git/mydafuhao 需求:inotify监控git仓库目录,发现有版本更新 ...

  6. https方式下 git push 每次都要输入密码的解决办法

    转载自:http://git.oschina.net/oschina/git-osc/issues/2586   作者:Zoker https方式每次都要输入密码,按照如下设置即可输入一次就不用再手输 ...

  7. js keycode

    参考 https://www.cnblogs.com/daysme/p/6272570.html

  8. C#调用dll提示"试图加载格式不正确的程序"原因及解决方法

    转载:https://blog.csdn.net/songyi160/article/details/51354660 程序在32位操作系统上运行正常,在64位操作系统上运行读卡功能提示”试图加载格式 ...

  9. 二叉搜索树的后序遍历序列(python)

    题目描述 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. # -*- coding:utf-8 -*- cl ...

  10. 让Ubuntu可以压缩/解压缩RAR文件

    ubuntu刚安装的时候是不能解压rar文件的,只有在安装了解压工具之后,才可以解压. 安装:sudo apt-get install unrar卸载:sudo apt-get remove unra ...