Git的提交日期或作者日期时间戳的解析是什么? [英] What is the resolution of Git's commit-date or author-date timestamps?

查看:415
本文介绍了Git的提交日期或作者日期时间戳的解析是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我可以看到,Git提交日期和作者日期只能准确到1秒钟。我想知道如果这是精确的,他们得到或可以得到时间戳,以毫秒或甚至微秒。

From what I can see, Git commit dates and author dates are only accurate to one second. I'm wondering if this is as precise as they get or can I get the timestamp in milliseconds or even microseconds.

此命令返回 UNIX Timestamp 使用第一个提交的提交哈希:

This command returns the UNIX Timestamp using the commit hash of the first commit:

git show -s --format="%ct" 2d9afdfb9e2fa9b349312734b462bb7d57a684ee

结果: 1421437899

Result: 1421437899

什么是GIT的提交日期或作者日期时间戳精度?

What is GIT's commit-date or author-date timestamp precision?

推荐答案

Git提交/作者日期的解决方案是1秒,正如 Alexey Ten 爱德华·汤姆森,也是解决Unix时间戳

The resolution of Git commit/author dates is 1 second, which, as pointed out by Alexey Ten and Edward Thomson, is also the resolution of Unix timestamps.

可以进行的一个有趣的体验是

An interesting experience you can conduct is to


  • 创建一个提交,并且

  • 修改它很快,而不改变任何东西(甚至不提交消息)。

您可能知道,修改提交实际创建一个新的提交。通常,新提交将具有不同的时间戳,因此与第一个提交的提交ID不同。但是,您可以编写一个创建提交并修改它的脚本,希望在同一个系统时钟秒内生成一个与第一个哈希值相同的提交。

As you may know, amending a commit actually creates a new commit. Normally, the new commit would have a different timestamp, and, therefore, a different commit ID from that of the first commit. However, you can write a script that creates the commit and amends it, hopefully within the same system-clock second, thereby producing a commit with the same hash as the first one.

首先,设置东西:

$ mkdir testGit
$ cd testGit
$ git init

然后将其写入脚本文件(称为 commitAmend.sh 以下)

Then write this to a script file (called commitAmend.sh below)

#!/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

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

Same timestamp, same hash!

这篇关于Git的提交日期或作者日期时间戳的解析是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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