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

标签 git date unix timestamp

据我所知,Git 提交日期和作者日期仅精确到一秒。我想知道这是否与他们得到的一样精确,或者我能否获得以毫秒甚至微秒为单位的时间戳。

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

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

结果:1421437899

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

最佳答案

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: jub0bs <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: jub0bs <xxxxxxxxxxx>
Date:   Fri Jan 30 14:25:58 2015 +0000

add README

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

关于git - Git 的提交日期或作者日期时间戳的分辨率是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28237043/

相关文章:

node.js - 如何在 github 操作工作流 ci 中通过 npm 安装私有(private) github 存储库

PHP : Not getting correct date difference

C套接字从接受返回的文件描述符中获取IP地址

linux - 如何在 shell 脚本 bash 中从属性文件调用变量

git - git rm 是否删除文件的所有历史记录?

git - 同步 TFS 和 GIT

git - 带有本地插件的 github 页面的干净系统

javascript - JS : Convert Today's Date to ISOString() with Fixed Time

r - 用c()函数强制日期的规则是什么

c - 使用相对路径打开文件