{"thread":{"id":"12040","subject":"referencing a revision at a certain date","startedAt":"2008-02-11T18:04:24Z","lastAt":"2008-02-11T18:57:13Z","messageCount":4,"participants":["David Madore","Jeff King","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"68415","messageId":"20080211180424.GA4905@clipper.ens.fr","threadId":"12040","inReplyTo":null,"subject":"referencing a revision at a certain date","fromName":"David Madore","fromEmail":"david.madore@ens.fr","sentAt":"2008-02-11T18:04:24Z","receivedAt":"2008-02-11T18:04:24Z","isPatch":false,"sender":{"key":"david.madore@ens.fr","avatar":null},"body":"Hi,\n\nI'm left quite confused by the git-rev-parse(1) man page, I wonder if\nsomeone can help me with this.\n\nI understand that if \"rev\" denotes a certain revision, then \"rev~42\"\nreferences the commit which is 42 generations back from rev.  What I'd\nlike to do is write something like \"rev~@{2008-01-18}\" (say) to get\nthe same thing but with the 42 being computed automatically so that\nthe commit in question is the latest possible (in commit date) before\n2008-01-18.  Is this possible?  If so, how?  If not, might I suggest\nthis as an addition for consideration?\n\nI thought \"rev@{2008-01-18}\" did this, but apparently it doesn't: it\nrequires a ref log of some kind, and I don't know how to make a ref\nlog (git-clone doesn't seem to copy them).\n\nSo, is there some way I can either generate a ref log by\nsystematically taking the first parent in each commit as per git-log\n--first-parent, OR (better) specify a revision directly that way?\n\nTypical problem I'm faced with:\n\nmizar david /tmp $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\nInitialized empty Git repository in /tmp/linux-2.6/.git/\nremote: Counting objects: 712898, done.\nremote: Compressing objects: 100% (124199/124199), done.\nIndexing 712898 objects...\nremote: Total 712898 (delta 591709), reused 708828 (delta 587713)\n 100% (712898/712898) done\nResolving 591709 deltas...\n 100% (591709/591709) done\nChecking 23757 files out...\n 100% (23757/23757) done\nmizar david /tmp $ cd linux-2.6\nmizar david /tmp/linux-2.6 $ git rev-parse 'master@{2008-02-01}'\nwarning: Log for 'master' only goes back to Mon, 11 Feb 2008 18:34:33 +0100.\n0000000000000000000000000000000000000000\nmizar david /tmp/linux-2.6 $ git rev-parse 'origin@{2008-02-01}'\nwarning: Log for 'origin' only goes back to Mon, 11 Feb 2008 18:34:32 +0100.\n0000000000000000000000000000000000000000\nmizar david /tmp/linux-2.6 $ git cat-file -p 'master~1126' | head -5\ntree a72dadd4a8b4957a4e21bf7ae38a763a71d6e274\nparent e1a9c9872dd004617555dff079b357a6ffd945e9\nparent c4772d99300a9fc13c86aaa370e630c5973664f6\nauthor Linus Torvalds <torvalds@linux-foundation.org> 1201821909 +1100\ncommitter Linus Torvalds <torvalds@linux-foundation.org> 1201821909 +1100\n\n=> there must be some intelligent way of finding this revision, but\nwhich is it?\n\nCheers,\n\n-- \n     David A. Madore\n    (david.madore@ens.fr,\n     http://www.madore.org/~david/ )\n"},{"id":"68417","messageId":"20080211182934.GA23351@sigill.intra.peff.net","threadId":"12040","inReplyTo":"20080211180424.GA4905@clipper.ens.fr","subject":"Re: referencing a revision at a certain date","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-11T18:29:34Z","receivedAt":"2008-02-11T18:29:34Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Feb 11, 2008 at 07:04:24PM +0100, David Madore wrote:\n\n> I understand that if \"rev\" denotes a certain revision, then \"rev~42\"\n> references the commit which is 42 generations back from rev.  What I'd\n> like to do is write something like \"rev~@{2008-01-18}\" (say) to get\n> the same thing but with the 42 being computed automatically so that\n> the commit in question is the latest possible (in commit date) before\n> 2008-01-18.  Is this possible?  If so, how?  If not, might I suggest\n> this as an addition for consideration?\n\nHow about --before=2008-01-18? As in,\n\n  git log --before=2008-01-18\n\nto start your log there (and \"git log -1 --before=2008-01-18\" if you\njust want that one commit).\n\n> I thought \"rev@{2008-01-18}\" did this, but apparently it doesn't: it\n> requires a ref log of some kind, and I don't know how to make a ref\n> log (git-clone doesn't seem to copy them).\n\nRef logs are a log of where your particular, local ref was pointing to.\nIn other words, it is a history not of the project commits, but of an\nindividual branch in your local repository. So you don't ask the reflog\nthings like \"which commit has a date at X\" but rather \"where was my\nmaster branch pointing at 3pm yesterday?\"\n\nAnd because they are purely a local matter, they don't get copied by\nclone.\n\n> So, is there some way I can either generate a ref log by\n> systematically taking the first parent in each commit as per git-log\n> --first-parent, OR (better) specify a revision directly that way?\n\nSo this question doesn't really make sense. You generate a ref log by\ndoing operations on a branch.\n\n-Peff\n"},{"id":"68418","messageId":"m3r6fje3q8.fsf@localhost.localdomain","threadId":"12040","inReplyTo":"20080211180424.GA4905@clipper.ens.fr","subject":"Re: referencing a revision at a certain date","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-02-11T18:40:39Z","receivedAt":"2008-02-11T18:40:39Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"David Madore <david.madore@ens.fr> writes:\n\n> I'm left quite confused by the git-rev-parse(1) man page, I wonder if\n> someone can help me with this.\n> \n> I understand that if \"rev\" denotes a certain revision, then \"rev~42\"\n> references the commit which is 42 generations back from rev.  \n\nTo be more exact it is 42 generations in straight, first-parent\nline. rev~3 is shortcut to rev^^^, which is shortcut to rev^1^1^1,\nwhere rev^1 means 1st parent of rev.\n\n> What I'd\n> like to do is write something like \"rev~@{2008-01-18}\" (say) to get\n> the same thing but with the 42 being computed automatically so that\n> the commit in question is the latest possible (in commit date) before\n> 2008-01-18.  Is this possible?  If so, how?  If not, might I suggest\n> this as an addition for consideration?\n\nThere is no direct mapping from date to a commit. So you cannot name a\ncommit (specify a revision) using date. Besides commit has two dates:\nauthor date (creation date), and commit date (modification date,\nroughly).\n\nBut you can can get commit closest to given date by combining the time\nlimiting with limiting number of commits, as described in \"Commit\nlimiting\" in git-rev-list(1) and git-log(1) manpages.\n\n  $ git log -n 1 --before=<date> <branch>\n\nwhich would return first commit older than <date>, starting from\n<branch>.\n\n> I thought \"rev@{2008-01-18}\" did this, but apparently it doesn't: it\n> requires a ref log of some kind, and I don't know how to make a ref\n> log (git-clone doesn't seem to copy them).\n\nReflogs are history (log) of a position of branch tip (ref) in a local\nrepository. Reflog stores sha-1 of top commit before and after change,\ndate of change, and description of command that changed it. For\nexample <branch>@{1} refers to position of branch before you did\nsomething locally to change it, were it commit, amending a commit,\nor for example fetching from remote repository.\n\n> So, is there some way I can either generate a ref log by\n> systematically taking the first parent in each commit as per git-log\n> --first-parent, OR (better) specify a revision directly that way?\n\nAgain: you cannot specify a commit in such way. You can find a (series\nof) commits which fulfill given condition.\n\nHTH\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"68421","messageId":"20080211185713.GA16898@clipper.ens.fr","threadId":"12040","inReplyTo":"m3r6fje3q8.fsf@localhost.localdomain","subject":"Re: referencing a revision at a certain date","fromName":"David Madore","fromEmail":"david.madore@ens.fr","sentAt":"2008-02-11T18:57:13Z","receivedAt":"2008-02-11T18:57:13Z","isPatch":false,"sender":{"key":"david.madore@ens.fr","avatar":null},"body":"On Mon, Feb 11, 2008 at 10:40:39AM -0800, Jakub Narebski wrote:\n> But you can can get commit closest to given date by combining the time\n> limiting with limiting number of commits, as described in \"Commit\n> limiting\" in git-rev-list(1) and git-log(1) manpages.\n> \n>   $ git log -n 1 --before=<date> <branch>\n> \n> which would return first commit older than <date>, starting from\n> <branch>.\n\nOK, thanks, I guess the --before part answers my question: so to get\nrevision \"rev\" back at date \"YYYY-MM-DD\" (always using first parents)\nI'd do\n\ngit rev-list rev -n 1 --first-parent --before=YYYY-MM-DD\n\nas in:\n\ngit checkout \"`git rev-list rev -n 1 --first-parent --before=YYYY-MM-DD`\"\n\nIt's a bit of a mouthful, but it does what I want (although I still\nthink a syntax such as rev~@{YYYY-MM-DD} or rev~{YYYY-MM-DD} or\nwhatever might prove useful: I imagine I'm not the first person to\nwish for something of the sort).\n\nThanks,\n\n-- \n     David A. Madore\n    (david.madore@ens.fr,\n     http://www.madore.org/~david/ )\n"}]}