Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git'的分辨率是多少;提交日期或作者日期时间戳?_Git_Date_Unix_Timestamp - Fatal编程技术网

Git'的分辨率是多少;提交日期或作者日期时间戳?

Git'的分辨率是多少;提交日期或作者日期时间戳?,git,date,unix,timestamp,Git,Date,Unix,Timestamp,据我所见,Git提交日期和作者日期只精确到一秒钟。我想知道这是否像他们得到的那样精确,或者我能以毫秒甚至微秒来获得时间戳 此命令使用第一次提交的提交哈希返回: git show -s --format="%ct" 2d9afdfb9e2fa9b349312734b462bb7d57a684ee 结果:1421437899 GIT的提交日期或作者日期时间戳精度是多少 是1秒;当git show稍微美化输出时,您可以使用git cat file命令查看原始提交信息。例如: % git cat-fi

据我所见,Git提交日期和作者日期只精确到一秒钟。我想知道这是否像他们得到的那样精确,或者我能以毫秒甚至微秒来获得时间戳

此命令使用第一次提交的提交哈希返回:

git show -s --format="%ct" 2d9afdfb9e2fa9b349312734b462bb7d57a684ee
结果:1421437899


GIT的提交日期或作者日期时间戳精度是多少

是1秒;当
git show
稍微美化输出时,您可以使用
git cat file
命令查看原始提交信息。例如:

% git cat-file commit HEAD
tree 340c0a26a5efed1f029fe1d719dd2f3beebdb910
parent 1ac5acdc695b837a921897a9d42acc75649cfd4f
author Edward Thomson <ethomson@edwardthomson.com> 1422564055 -0600
committer Edward Thomson <ethomson@edwardthomson.com> 1422564055 -0600

My witty comment goes here.
%git cat文件提交头
树340CA26A5EFED1F029FE1D719DD2F3BEEBDB910
父级1AC5ACDC695B837A921897A9D42AC75649CFD4F
作者爱德华·汤姆森1422564055-0600
提交人Edward Thomson 1422564055-0600
我的妙语就在这里。

您确实可以看到,这是一个分辨率为1秒的Unix时间戳。

Git提交/作者日期的分辨率为1秒,正如和所指出的,这也是

你可以做的一个有趣的实验是

  • 创建提交,然后
  • 非常快速地修改它,而不更改任何内容(甚至不更改提交消息)
如你所知。通常,新提交的时间戳不同,因此提交ID与第一次提交的不同。但是,您可以编写一个脚本,在相同的系统时钟秒内创建提交并修改它(幸运的是!),从而生成一个哈希与第一次提交相同的提交

首先,把事情安排好:

$mkdir testGit
$cd testGit
$git init
然后将其写入脚本文件(下面称为
commitAmend.sh

#/垃圾箱/垃圾箱
#创建内容并提交
printf“Hello World.\n”>README.md
git add README.md
git提交-m“添加自述”
吉特日志
#修改承诺
git提交--修改--不编辑
吉特日志
然后运行它:

$sh commitAmend.sh
[master(root提交)11e59c4]添加自述
1个文件已更改,1个插入(+)
创建模式100644 README.md
提交11e59c47ba2f9754eaf3eb7693a33c22651d57c7
作者:jub0bs
日期:2015年1月30日星期五14:25:58+0000
添加自述
[master 11e59c4]添加自述
日期:2015年1月30日星期五14:25:58+0000
1个文件已更改,1个插入(+)
创建模式100644 README.md
提交11e59c47ba2f9754eaf3eb7693a33c22651d57c7
作者:jub0bs
日期:2015年1月30日星期五14:25:58+0000
添加自述

相同的时间戳,相同的哈希

它只是unix时间戳,和时间戳一样精确。实际上,git commit是一种特殊格式的文本,时间存储为timestampsInteresting+1谢谢你的详细回答。那么,有没有一种方法可以通过使用Git add获得文件添加到Git的时间?@Jack No。暂存文件不会记录任何相关的时间戳。在该链接中,@Jubobs
git add
的精彩解释解释解释了暂存文件时会发生什么。我认为第一次提交的UNIX时间戳对于我要做的事情来说已经足够好了。我有一个由合并后挂钩触发的数据库迁移脚本,我希望所有.sql迁移文件都以正确的顺序运行,但如果将多个文件添加到迁移目录并同时提交,它们都具有相同的时间戳,这是一个问题,因为我将时间戳映射到具有文件路径的键作为assoc数组的值,然后按键排序。@杰克可能值得在另一个问题上寻求帮助,但我恐怕无法回答这个问题。