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

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


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 experiment that 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 within the same system-clock second (with a bit of luck!), thereby producing a commit whose hash is the same as the first commit's.

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 commitprintf "Hello World.\n" > README.mdgit add README.mdgit commit -m "add README"git log# amend the commitgit commit --amend --no-editgit log

and run it:

$ sh commitAmend.sh[master (root-commit) 11e59c4] add README 1 file changed, 1 insertion(+) create mode 100644 README.mdcommit 11e59c47ba2f9754eaf3eb7693a33c22651d57c7Author: 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.mdcommit 11e59c47ba2f9754eaf3eb7693a33c22651d57c7Author: jub0bs <xxxxxxxxxxx>Date:   Fri Jan 30 14:25:58 2015 +0000add README

Same timestamp, same hash!


It is one second; while git-show is prettifying the output a bit, you can see the raw commit information using the git-cat-file command. For example:

% git cat-file commit HEADtree 340c0a26a5efed1f029fe1d719dd2f3beebdb910parent 1ac5acdc695b837a921897a9d42acc75649cfd4fauthor Edward Thomson <ethomson@edwardthomson.com> 1422564055 -0600committer Edward Thomson <ethomson@edwardthomson.com> 1422564055 -0600My witty comment goes here.

You can see indeed that this is a Unix timestamp with a resolution of 1 second.