git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to determine age of HEAD commit

From
RGRoger Gammans <rgammans@gammascience.co.uk>
Date
Dec 8, 2019, 14:07 UTC
Message-ID
<0a578dce37e8802b2022df80c336f61a264a33e3.camel@gammascience.co.uk>
In-Reply-To
<956e2efe-3426-f61e-7686-5416b51931b9@iee.email>
On Sun, 2019-12-08 at 12:09 +0000, Philip Oakley wrote:
> Is there a command that does return the numeric agedness of a commit 
> (e.g. now - commit_date, in seconds)?
Hi

I don't know a specific command for the age. But `git cat-file commit HEAD`, will give you the commit's timestamps in seconds from the the epoch. (Plus some timezone info).

I can construct a bash script, shown below (warning: only had the most rudimentary testing), which turns that into an age. For your use case you might be better getting yesterdays unix-timestamp from date, if GNU date is available, and directly comparing it to the commit timestamp.

------ #!/bin/bash

now=$(date +"%s") commit=$(git cat-file commit HEAD | grep committer) commit=${commit##*>} commit=${commit%%+*} echo $(( $now-$commit )) #--------------

-- 
Roger Gammans <rgammans@gammascience.co.uk>
Previous: Philip OakleyNext: Philip Oakley
Message 2 of 3 in “How to determine age of HEAD commit”
  1. Philip OakleyDec 8, 2019
  2. Roger GammansDec 8, 2019
  3. Philip OakleyDec 8, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.