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

Re: Why do dates in refspecs require the reflog?

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 30, 2014, 20:31 UTC
Message-ID
<xmqq61csswvv.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CAHd499Cvy=zi=9utoZ2bEgdSUTjkveHMP2OvVFPBHq7W2MuoZQ@mail.gmail.com>
Robert Dailey <rcdailey.lists@gmail.com> writes:
Show 15 quoted lines
> I was surprised to find today that the following didn't work as expected:
>
> $ git show master@{"1 year ago"}:Path/To/File.h
>
> It gave me the following warning which did not make the problem obvious at all:
> warning: Log for 'master' only goes back to Mon, 8 Sep 2014 12:08:44 -0500.
>
> What it is trying to tell me (and I only found this out after a lot of
> poking and prodding around Google) is that I can't refer to a commit
> by date if it extends beyond the range of the reflog.
>
> I don't understand why this requirement is in place. Each commit has a
> time stamp, so in theory it should be possible to calculate an
> absolute date from the duration specified in the refspec and grab the
> commit from `git log` from that.

The reason is because the dates on the commit object itself do not have anything to do with the question you are asking with the "@{date}" notation. master@{at-this-time} notation specifies the commit that was at the tip of your master branch at the specified time, and that information can _only_ come from your own reflogs.

If you did this in your copy of git.git repository today:
    $ git checkout -b test e83c5163316f89bfbd
    $ sleep 3600
    $ git reset --hard master
    $ git show test@{20.minutes.ago}

you will see e83c516, even though that commit is almost 10 years old. Now what was at the tip of your "test" branch on April 7th, 2005? The answer is "nothing", as most likely your 'test' branch did not exist back then.

And that is why "git show test@{2005/04/07}" will not (and should not) look at the timestamps in commit objects.

Previous: Stefan BellerNext: Junio C Hamano
Message 3 of 9 in “Why do dates in refspecs require the reflog?”
  1. Robert DaileyDec 30, 2014
  2. Stefan BellerDec 30, 2014
  3. Junio C HamanoDec 30, 2014
  4. Junio C HamanoDec 30, 2014
  5. Michael HaggertyDec 30, 2014
  6. Junio C HamanoDec 30, 2014
  7. Robert DaileyDec 30, 2014
  8. Jeff KingDec 31, 2014
  9. Michael HaggertyDec 30, 2014

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.