Search code examples
javagitgit-plumbing

Git Commit Object Author and Commiter Fields


I am trying to make a server using Java that runs on a Linux machine and I would like my server to support Git in a similar fashion to GitHub. I have figured out a lot of things to achieve this but there is one thing I would like to know...

Assuming I have the following Git object (with a header) deflated and stored in the file system.

tree d35e45b7a3ec1bfd4d91b87c16d08fc4effc6dba
parent 385f73f0f5d38c6258a7d55038c9ceb24cd63157
author ThePyroEagle <exampleEmail@example.com> 1418335844 +0000
commiter ThePyroEagle <exampleEmail@example.com> 1418335844 +0000

What does "1418335844 +0000" at the end mean?

I thought this might be a timestamp in milliseconds, but when I parsed it I got "17 January 1970" using the following code.

Date date = new Date(1418335844L);
System.out.printf("Current Time: %s\n",
        (new SimpleDateFormat("dd MMMM yyyy")).format(date));

Whatever this may be, how would I go about parsing it?


Solution

  • The git commit date format states:

    Git internal format

    It is <unix timestamp> <time zone offset>, where:

    • <unix timestamp> is the number of seconds since the UNIX epoch.
    • <time zone offset> is a positive or negative offset from UTC. For example CET (which is 2 hours ahead UTC) is +0200.

    See: