{"thread":{"id":"38265","subject":"Why do dates in refspecs require the reflog?","startedAt":"2014-12-30T20:12:15Z","lastAt":"2014-12-31T01:26:16Z","messageCount":9,"participants":["Robert Dailey","Stefan Beller","Junio C Hamano","Michael Haggerty","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"254213","messageId":"CAHd499Cvy=zi=9utoZ2bEgdSUTjkveHMP2OvVFPBHq7W2MuoZQ@mail.gmail.com","threadId":"38265","inReplyTo":null,"subject":"Why do dates in refspecs require the reflog?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2014-12-30T20:12:15Z","receivedAt":"2014-12-30T20:12:15Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"I was surprised to find today that the following didn't work as expected:\n\n$ git show master@{\"1 year ago\"}:Path/To/File.h\n\nIt gave me the following warning which did not make the problem obvious at all:\nwarning: Log for 'master' only goes back to Mon, 8 Sep 2014 12:08:44 -0500.\n\nWhat it is trying to tell me (and I only found this out after a lot of\npoking and prodding around Google) is that I can't refer to a commit\nby date if it extends beyond the range of the reflog.\n\nI don't understand why this requirement is in place. Each commit has a\ntime stamp, so in theory it should be possible to calculate an\nabsolute date from the duration specified in the refspec and grab the\ncommit from `git log` from that.\n\nI can only assume I'm oversimplifying things and that there is a good\nreason for this. If I can't get this to work, how can I view the\ncontents of a file at a specified relative time frame as I have done\nabove?\n"},{"id":"254214","messageId":"CAGZ79kZteMXLaQowxNdrXd-ULbmZQ=AuyCyz0w6dLJC68ThxnA@mail.gmail.com","threadId":"38265","inReplyTo":"CAHd499Cvy=zi=9utoZ2bEgdSUTjkveHMP2OvVFPBHq7W2MuoZQ@mail.gmail.com","subject":"Re: Why do dates in refspecs require the reflog?","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2014-12-30T20:16:13Z","receivedAt":"2014-12-30T20:16:13Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Tue, Dec 30, 2014 at 12:12 PM, Robert Dailey\n<rcdailey.lists@gmail.com> wrote:\n> I was surprised to find today that the following didn't work as expected:\n>\n> $ git show master@{\"1 year ago\"}:Path/To/File.h\n>\n> It gave me the following warning which did not make the problem obvious at all:\n> warning: Log for 'master' only goes back to Mon, 8 Sep 2014 12:08:44 -0500.\n>\n> What it is trying to tell me (and I only found this out after a lot of\n> poking and prodding around Google) is that I can't refer to a commit\n> by date if it extends beyond the range of the reflog.\n>\n> I don't understand why this requirement is in place. Each commit has a\n> time stamp, so in theory it should be possible to calculate an\n> absolute date from the duration specified in the refspec and grab the\n> commit from `git log` from that.\n\nBecause the commit may have existed at a certain date, but not in the branch.\nIt may have been merged at a later time. I am not sure if this is the\nactual reason though.\n\n\n>\n> I can only assume I'm oversimplifying things and that there is a good\n> reason for this. If I can't get this to work, how can I view the\n> contents of a file at a specified relative time frame as I have done\n> above?\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"254215","messageId":"xmqq61csswvv.fsf@gitster.dls.corp.google.com","threadId":"38265","inReplyTo":"CAHd499Cvy=zi=9utoZ2bEgdSUTjkveHMP2OvVFPBHq7W2MuoZQ@mail.gmail.com","subject":"Re: Why do dates in refspecs require the reflog?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-30T20:31:00Z","receivedAt":"2014-12-30T20:31:00Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Robert Dailey <rcdailey.lists@gmail.com> writes:\n\n> I was surprised to find today that the following didn't work as expected:\n>\n> $ git show master@{\"1 year ago\"}:Path/To/File.h\n>\n> It gave me the following warning which did not make the problem obvious at all:\n> warning: Log for 'master' only goes back to Mon, 8 Sep 2014 12:08:44 -0500.\n>\n> What it is trying to tell me (and I only found this out after a lot of\n> poking and prodding around Google) is that I can't refer to a commit\n> by date if it extends beyond the range of the reflog.\n>\n> I don't understand why this requirement is in place. Each commit has a\n> time stamp, so in theory it should be possible to calculate an\n> absolute date from the duration specified in the refspec and grab the\n> commit from `git log` from that.\n\nThe reason is because the dates on the commit object itself do not\nhave anything to do with the question you are asking with the\n\"@{date}\" notation.  master@{at-this-time} notation specifies the\ncommit that was at the tip of your master branch at the specified\ntime, and that information can _only_ come from your own reflogs.\n\nIf you did this in your copy of git.git repository today:\n\n    $ git checkout -b test e83c5163316f89bfbd\n    $ sleep 3600\n    $ git reset --hard master\n    $ git show test@{20.minutes.ago}\n\nyou will see e83c516, even though that commit is almost 10 years\nold.  Now what was at the tip of your \"test\" branch on April 7th,\n2005?  The answer is \"nothing\", as most likely your 'test' branch\ndid not exist back then.\n\nAnd that is why \"git show test@{2005/04/07}\" will not (and should\nnot) look at the timestamps in commit objects.\n"},{"id":"254218","messageId":"xmqq1tngsw55.fsf@gitster.dls.corp.google.com","threadId":"38265","inReplyTo":"CAHd499Cvy=zi=9utoZ2bEgdSUTjkveHMP2OvVFPBHq7W2MuoZQ@mail.gmail.com","subject":"Re: Why do dates in refspecs require the reflog?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-30T20:47:02Z","receivedAt":"2014-12-30T20:47:02Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Robert Dailey <rcdailey.lists@gmail.com> writes:\n\n> ... how can I view the\n> contents of a file at a specified relative time frame ...\n\n\"git log --until=A --since=B master\" asks Git to start traversing\nthe history backward from the tip of your current 'master' branch,\nwithout showing anything until it finds a commit with timestamp A\n(or before), and then show the commits it finds during the traversal\nuntil it finds a commit with timestamp B (or before) and then stop.\n\nWhich I think is the closest thing you are asking for.\n\nNote that there is *no* guarantee that any of these commits you find\nthat way was actually at the tip of the public history (i.e. the one\ncasual users would have seen after running \"git clone\" at that time).\n\nThe committer may have started working at around time B, worked for\nquite some time, and pushed the result out way after time A.  Then\nthe first time general public observed the commits you find in that\ntime range could be after time A by many weeks, which is perfectly\nnormal in the real, distributed, world.\n"},{"id":"254219","messageId":"54A310AB.7050701@alum.mit.edu","threadId":"38265","inReplyTo":"CAHd499Cvy=zi=9utoZ2bEgdSUTjkveHMP2OvVFPBHq7W2MuoZQ@mail.gmail.com","subject":"Re: Why do dates in refspecs require the reflog?","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-12-30T20:52:59Z","receivedAt":"2014-12-30T20:52:59Z","isPatch":false,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 12/30/2014 09:12 PM, Robert Dailey wrote:\n> I was surprised to find today that the following didn't work as expected:\n> \n> $ git show master@{\"1 year ago\"}:Path/To/File.h\n> \n> It gave me the following warning which did not make the problem obvious at all:\n> warning: Log for 'master' only goes back to Mon, 8 Sep 2014 12:08:44 -0500.\n> \n> What it is trying to tell me (and I only found this out after a lot of\n> poking and prodding around Google) is that I can't refer to a commit\n> by date if it extends beyond the range of the reflog.\n> \n> I don't understand why this requirement is in place. Each commit has a\n> time stamp, so in theory it should be possible to calculate an\n> absolute date from the duration specified in the refspec and grab the\n> commit from `git log` from that.\n> \n> I can only assume I'm oversimplifying things and that there is a good\n> reason for this. If I can't get this to work, how can I view the\n> contents of a file at a specified relative time frame as I have done\n> above?\n\nThe syntax you are using,\n\n    master@{\"1 year ago\"}\n\ntells you \"what commit was the master branch in this clone pointing at\none year ago?\" What you presumably expected is \"What is the last [1]\ncommit that is *currently* on the master branch that was committed at\nleast one year ago?\"\n\nThe command to ask your question is something like\n\n    git log --date-order --before='1 year ago' -1 master\n\nThere is yet a third similar question: \"What is the last commit that is\ncurrently on the master branch that was *authored* at least one year\nago? Please note that this question is even subtler, because author\ntimestamps are often out-of-order even on a single branch (whereas\ncommit timestamps are usually in order). I don't know of a simple git\ncommand to answer this question.\n\nMichael\n\n[1] Note that \"last\" is a bit subtle, because the history of \"master\"\nprobably contains multiple branches with interleaved dates. So depending\non your needs, you might want to add an option like \"--first-parent\"\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\n"},{"id":"254221","messageId":"xmqqppb0rh63.fsf@gitster.dls.corp.google.com","threadId":"38265","inReplyTo":"54A310AB.7050701@alum.mit.edu","subject":"Re: Why do dates in refspecs require the reflog?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-30T20:55:48Z","receivedAt":"2014-12-30T20:55:48Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Haggerty <mhagger@alum.mit.edu> writes:\n\n> There is yet a third similar question: \"What is the last commit that is\n> currently on the master branch that was *authored* at least one year\n> ago? Please note that this question is even subtler, because author\n> timestamps are often out-of-order even on a single branch (whereas\n> commit timestamps are usually in order). I don't know of a simple git\n> command to answer this question.\n\n--author-date-order?\n"},{"id":"254223","messageId":"CAHd499Bt6_SOkj9Pp+GcLGnwDUR-pgr_YKt4yqZBAHjX+vkM8Q@mail.gmail.com","threadId":"38265","inReplyTo":"xmqqppb0rh63.fsf@gitster.dls.corp.google.com","subject":"Re: Why do dates in refspecs require the reflog?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2014-12-30T21:39:53Z","receivedAt":"2014-12-30T21:39:53Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"On Tue, Dec 30, 2014 at 2:55 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Michael Haggerty <mhagger@alum.mit.edu> writes:\n>\n>> There is yet a third similar question: \"What is the last commit that is\n>> currently on the master branch that was *authored* at least one year\n>> ago? Please note that this question is even subtler, because author\n>> timestamps are often out-of-order even on a single branch (whereas\n>> commit timestamps are usually in order). I don't know of a simple git\n>> command to answer this question.\n>\n> --author-date-order?\n\nThanks to everyone for explaining this, it makes sense now. I've been\nusing git a long time and I found this rather unintuitive because my\nmindset was not on \"reflog\" but instead \"git log\", so there was a huge\nmisunderstanding.\n\nIs it valid to use durations (as Michael has done) in the --since and\n--until options to `git log`? It also feels like there should be a\nshorthand for the `git log` usage in conjunction with `git show`... I\ncould probably make an alias for it. But basically what I'm looking\nfor is this (please correct me if I'm wrong):\n\n$ git log --since='1 year ago' -1\n(somehow grab the SHA1 from the commit printed above)\n$ git show <grabbed SHA1>:Path/To/File.h\n(path to file is parameterized above)\n\nSo basically these two commands together could be stuffed into an alias:\n\n$ git log-show '1 year ago' Path/To/File.h\n\nThis is the best I can come up with for now. Note also that \"accuracy\"\nisn't important here, just \"closest matching\". I appreciate and\nunderstand that things can be out of order (as far as commit\ntimestamps go, since you can rebase and reorder things). Accuracy for\nthese things aren't too important because usually I will use them for\nbisect or an approximation of where in time I want to see a file for\ncode reference (i.e. how a function \"used to look back then\").\n"},{"id":"254224","messageId":"54A31DEB.7020900@alum.mit.edu","threadId":"38265","inReplyTo":"xmqqppb0rh63.fsf@gitster.dls.corp.google.com","subject":"Re: Why do dates in refspecs require the reflog?","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-12-30T21:49:31Z","receivedAt":"2014-12-30T21:49:31Z","isPatch":false,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 12/30/2014 09:55 PM, Junio C Hamano wrote:\n> Michael Haggerty <mhagger@alum.mit.edu> writes:\n> \n>> There is yet a third similar question: \"What is the last commit that is\n>> currently on the master branch that was *authored* at least one year\n>> ago? Please note that this question is even subtler, because author\n>> timestamps are often out-of-order even on a single branch (whereas\n>> commit timestamps are usually in order). I don't know of a simple git\n>> command to answer this question.\n> \n> --author-date-order?\n\nDoes --author-date-order cause --before/--after/--since/--until to use\nauthor dates rather than commit dates? The documentation doesn't mention\nthat effect. If not, then it doesn't help much.\n\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\n"},{"id":"254239","messageId":"20141231012615.GA8852@peff.net","threadId":"38265","inReplyTo":"CAHd499Bt6_SOkj9Pp+GcLGnwDUR-pgr_YKt4yqZBAHjX+vkM8Q@mail.gmail.com","subject":"Re: Why do dates in refspecs require the reflog?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-12-31T01:26:16Z","receivedAt":"2014-12-31T01:26:16Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Dec 30, 2014 at 03:39:53PM -0600, Robert Dailey wrote:\n\n> It also feels like there should be a\n> shorthand for the `git log` usage in conjunction with `git show`... I\n> could probably make an alias for it.\n\nOne thing I didn't see mentioned in this thread is that the question\n\"show me the commit closest to time X\" does not have a single answer.\nWhen there are branches, there may be many such answers, one for each\nline of simultaneous development.\n\nSo people tend not to ask that question[1], and therefore nobody\nbothered to make a convenient shorthand for it.\n\n-Peff\n\n[1] What do they ask instead? I find most of my older queries for\n    commits are satisfied following parent links from well-known points.\n    E.g., finding where topic X was merged, and then walking backwards\n    using \"^2\" to see the tip of the original topic.\n\n    If I am looking for information about a particular file about a year\n    ago, I often turn to \"-S\" or git-blame (actually, \"tig blame\" in my\n    case, which lets you walk backwards interactively).\n\n    But of course the exact query will depend on just what it is you\n    want to know. :)\n"}]}