git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Robert Dailey <rcdailey.lists@gmail.com>, Git <git@vger.kernel.org>
Subject: Re: Why do dates in refspecs require the reflog?
Date: Tue, 30 Dec 2014 21:52:59 +0100	[thread overview]
Message-ID: <54A310AB.7050701@alum.mit.edu> (raw)
In-Reply-To: <CAHd499Cvy=zi=9utoZ2bEgdSUTjkveHMP2OvVFPBHq7W2MuoZQ@mail.gmail.com>

On 12/30/2014 09:12 PM, Robert Dailey wrote:
> 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.
> 
> I can only assume I'm oversimplifying things and that there is a good
> reason for this. If I can't get this to work, how can I view the
> contents of a file at a specified relative time frame as I have done
> above?

The syntax you are using,

    master@{"1 year ago"}

tells you "what commit was the master branch in this clone pointing at
one year ago?" What you presumably expected is "What is the last [1]
commit that is *currently* on the master branch that was committed at
least one year ago?"

The command to ask your question is something like

    git log --date-order --before='1 year ago' -1 master

There is yet a third similar question: "What is the last commit that is
currently on the master branch that was *authored* at least one year
ago? Please note that this question is even subtler, because author
timestamps are often out-of-order even on a single branch (whereas
commit timestamps are usually in order). I don't know of a simple git
command to answer this question.

Michael

[1] Note that "last" is a bit subtle, because the history of "master"
probably contains multiple branches with interleaved dates. So depending
on your needs, you might want to add an option like "--first-parent"

-- 
Michael Haggerty
mhagger@alum.mit.edu

  parent reply	other threads:[~2014-12-30 20:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-30 20:12 Why do dates in refspecs require the reflog? Robert Dailey
2014-12-30 20:16 ` Stefan Beller
2014-12-30 20:31 ` Junio C Hamano
2014-12-30 20:47 ` Junio C Hamano
2014-12-30 20:52 ` Michael Haggerty [this message]
2014-12-30 20:55   ` Junio C Hamano
2014-12-30 21:39     ` Robert Dailey
2014-12-31  1:26       ` Jeff King
2014-12-30 21:49     ` Michael Haggerty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54A310AB.7050701@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=git@vger.kernel.org \
    --cc=rcdailey.lists@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).