Jack Jack -4 years ago 167
Git Question

What is the resolution of Git's commit-date or author-date timestamps?

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.

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

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


Result: 1421437899

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

Answer Source

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

  • create a commit, and
  • amend it very quickly, without changing anything (not even the commit message).

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.

First, set things up:

$ mkdir testGit
$ cd testGit
$ git init

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

and run it:

$ 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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download