Git commit date

Git

Git Problem Overview


Other than parsing git log for the date string, is there a Git native way to report the date of a certain commit?

Git Solutions


Solution 1 - Git

The show command may be what you want. Try

git show -s --format=%ci <commit>

Other formats for the date string are available as well. Check the manual page for details.

Solution 2 - Git

If you want to see only the date of a tag you'd do:

git show -s --format=%ci <mytagname>^{commit}

which gives: 2013-11-06 13:22:37 +0100

Or do:

git show -s --format=%ct <mytagname>^{commit}

which gives UNIX timestamp: 1383740557

Solution 3 - Git

If you like to have the timestamp without the timezone but local timezone do

git log -1 --format=%cd --date=local

Which gives this depending on your location

Mon Sep 28 12:07:37 2015

Solution 4 - Git

You can use the git show command.

To get the last commit date from git repository in a long(Unix epoch timestamp):

  • Command: git show -s --format=%ct
  • Result: 1605103148

Note: You can visit the git-show documentation to get a more detailed description of the options.

Solution 5 - Git

In case that you want to format the date (or hour) by yourself:

git show -s --date=format:'%Y%m%d-%H%M' --format=%cd  <commit id | default is the last commit>

# example output:
20210712-1948

Solution 6 - Git

if you got troubles with windows cmd command and .bat just escape percents like that

git show -s --format=%%ct

> The % character has a special meaning for command line parameters and FOR parameters. To treat a percent as a regular character, double it: %%

Syntax : Escape Characters, Delimiters and Quotes

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSamer BunaView Question on Stackoverflow
Solution 1 - GitTim HeniganView Answer on Stackoverflow
Solution 2 - GitMarcus PhilipView Answer on Stackoverflow
Solution 3 - GitschoetbiView Answer on Stackoverflow
Solution 4 - GitKeshav LodhiView Answer on Stackoverflow
Solution 5 - GitdsaydonView Answer on Stackoverflow
Solution 6 - GitAndrey TikhonovView Answer on Stackoverflow