从我所看到的,Git提交日期和作者日期仅精确到一秒。我想知道这是否与它们得到的一样精确,或者我能以毫秒甚至微秒获得时间戳。
此命令使用第一次提交的提交哈希值返回UNIX Timestamp:
git show -s --format="%ct" 2d9afdfb9e2fa9b349312734b462bb7d57a684ee
结果: 1421437899
GIT的提交日期或作者日期时间戳精度是多少?
答案 0 :(得分:13)
Git提交/作者日期的解决方案是1秒,正如Alexey Ten和Edward Thomson所指出的那样,也是the resolution of Unix timestamps。
您可以进行的有趣实验是
如您所知,amending a commit actually creates a new commit。通常,新提交将具有不同的时间戳,因此,与第一次提交的提交ID不同。但是,您可以编写一个创建提交的脚本,并在相同的系统时钟秒内修改它(运气好!),从而产生一个提交,其哈希值与第一次提交相同。
首先,进行设置:
$ mkdir testGit
$ cd testGit
$ git init
然后将其写入脚本文件(下面称为commitAmend.sh
)
#!/bin/sh
# create content and commit
printf "Hello World.\n" > README.md
git add README.md
git commit -m "add README"
git log
# amend the commit
git commit --amend --no-edit
git log
并运行它:
$ sh commitAmend.sh
[master (root-commit) 11e59c4] add README
1 file changed, 1 insertion(+)
create mode 100644 README.md
commit 11e59c47ba2f9754eaf3eb7693a33c22651d57c7
Author: Jubobs <xxxxxxxxxxx>
Date: Fri Jan 30 14:25:58 2015 +0000
add README
[master 11e59c4] add README
Date: Fri Jan 30 14:25:58 2015 +0000
1 file changed, 1 insertion(+)
create mode 100644 README.md
commit 11e59c47ba2f9754eaf3eb7693a33c22651d57c7
Author: Jubobs <xxxxxxxxxxx>
Date: Fri Jan 30 14:25:58 2015 +0000
add README
相同的时间戳,相同的哈希!
答案 1 :(得分:5)
是一秒钟;虽然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.
您确实可以看到这是一个分辨率为1秒的Unix时间戳。