{"thread":{"id":"33241","subject":"Which file is older in history?","startedAt":"2013-03-20T20:21:38Z","lastAt":"2013-03-21T13:26:20Z","messageCount":7,"participants":["Ramkumar Ramachandra","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"211820","messageId":"CALkWK0nTjoR9qBY-hnkrDKnyf8088ZDJ1LK_zNqAoAB7ndvaww@mail.gmail.com","threadId":"33241","inReplyTo":null,"subject":"Which file is older in history?","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-03-20T20:21:38Z","receivedAt":"2013-03-20T20:21:38Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nI want to compare two files in a git repository and tell which one was\nintroduced into the repository earlier, assuming that they're in the\nsame history line (by ancestry, not timestamp).  The naive way to do\nthis is to find the individual commits that introduced the files\n(`rev-list HEAD -- <filename> | tail -n 1`), and query whether there\nare commits between them (`rev-list commit1 ^commit2`). However, this\nis slow.  What about bisecting the history until we find a tree that\ncontains one file but not the other?\n\nThanks.\n\nRam\n"},{"id":"211827","messageId":"7vobeddcjq.fsf@alter.siamese.dyndns.org","threadId":"33241","inReplyTo":"CALkWK0nTjoR9qBY-hnkrDKnyf8088ZDJ1LK_zNqAoAB7ndvaww@mail.gmail.com","subject":"Re: Which file is older in history?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-03-20T20:46:49Z","receivedAt":"2013-03-20T20:46:49Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> I want to compare two files in a git repository and tell which one was\n> introduced into the repository earlier, assuming that they're in the\n> same history line (by ancestry, not timestamp).  The naive way to do\n> this is to find the individual commits that introduced the files\n> (`rev-list HEAD -- <filename> | tail -n 1`), and...\n\nThis must be a trick question but the naïve way I think of is\n\n\tgit log --diff-filter=A -- path1 path2\n"},{"id":"211853","messageId":"CALkWK0nRgzNYViKSx97OyHVOQmFN61Ex9EUvr1JK-0=GX=uX0w@mail.gmail.com","threadId":"33241","inReplyTo":"7vobeddcjq.fsf@alter.siamese.dyndns.org","subject":"Re: Which file is older in history?","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-03-21T11:59:39Z","receivedAt":"2013-03-21T11:59:39Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> Ramkumar Ramachandra <artagnon@gmail.com> writes:\n>\n>> I want to compare two files in a git repository and tell which one was\n>> introduced into the repository earlier, assuming that they're in the\n>> same history line (by ancestry, not timestamp).  The naive way to do\n>> this is to find the individual commits that introduced the files\n>> (`rev-list HEAD -- <filename> | tail -n 1`), and...\n>\n> This must be a trick question but the naïve way I think of is\n>\n>         git log --diff-filter=A -- path1 path2\n\nThanks, I didn't know about --diff-filter.  I'll need one extra step\nto figure out which commit corresponds to the introduction of which\nfile, no?\n"},{"id":"211854","messageId":"20130321122130.GA22607@sigill.intra.peff.net","threadId":"33241","inReplyTo":"CALkWK0nRgzNYViKSx97OyHVOQmFN61Ex9EUvr1JK-0=GX=uX0w@mail.gmail.com","subject":"Re: Which file is older in history?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-03-21T12:21:30Z","receivedAt":"2013-03-21T12:21:30Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 21, 2013 at 05:29:39PM +0530, Ramkumar Ramachandra wrote:\n\n> > This must be a trick question but the naïve way I think of is\n> >\n> >         git log --diff-filter=A -- path1 path2\n> \n> Thanks, I didn't know about --diff-filter.  I'll need one extra step\n> to figure out which commit corresponds to the introduction of which\n> file, no?\n\nMaybe\n\n  git log --format=%H --name-status --diff-filter=A -- path1 path2 |\n  perl -lne '\n    if (/[0-9a-f]{40}/) { $commit = $& }\n    elsif (/^A\\t(.*)/) { $h{$1} = $commit }\n    END { print \"$h{$_} $_\" for keys(%h) }\n  '\n\n?\n\n-Peff\n"},{"id":"211855","messageId":"20130321122428.GB22607@sigill.intra.peff.net","threadId":"33241","inReplyTo":"20130321122130.GA22607@sigill.intra.peff.net","subject":"Re: Which file is older in history?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-03-21T12:24:28Z","receivedAt":"2013-03-21T12:24:28Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 21, 2013 at 08:21:30AM -0400, Jeff King wrote:\n\n> On Thu, Mar 21, 2013 at 05:29:39PM +0530, Ramkumar Ramachandra wrote:\n> \n> > > This must be a trick question but the naïve way I think of is\n> > >\n> > >         git log --diff-filter=A -- path1 path2\n> > \n> > Thanks, I didn't know about --diff-filter.  I'll need one extra step\n> > to figure out which commit corresponds to the introduction of which\n> > file, no?\n> \n> Maybe\n> \n>   git log --format=%H --name-status --diff-filter=A -- path1 path2 |\n>   perl -lne '\n>     if (/[0-9a-f]{40}/) { $commit = $& }\n>     elsif (/^A\\t(.*)/) { $h{$1} = $commit }\n>     END { print \"$h{$_} $_\" for keys(%h) }\n>   '\n\nActually, I only looked at your question, not the original point, which\nwas not which commit was which, but which one was older. If you just\nwant to know which is older, then just:\n\n  git log --format=%H --name-status --diff-filter=A -- path1 path2 |\n  grep ^A |\n  tail -1\n\nwhich uses the regular traversal order (i.e., mostly following commit\ntimestamps). You can use --topo-order if you want to make sure it\nfollows the graph structure.\n\n-Peff\n"},{"id":"211857","messageId":"CALkWK0nOzUXk0cFh8GCHc=YqLkRJ2XNFgU_tOsua81ROK99mXw@mail.gmail.com","threadId":"33241","inReplyTo":"20130321122428.GB22607@sigill.intra.peff.net","subject":"Re: Which file is older in history?","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-03-21T12:32:32Z","receivedAt":"2013-03-21T12:32:32Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Jeff King wrote:\n> On Thu, Mar 21, 2013 at 08:21:30AM -0400, Jeff King wrote:\n>\n>> On Thu, Mar 21, 2013 at 05:29:39PM +0530, Ramkumar Ramachandra wrote:\n>>\n>> > > This must be a trick question but the naïve way I think of is\n>> > >\n>> > >         git log --diff-filter=A -- path1 path2\n>> >\n>> > Thanks, I didn't know about --diff-filter.  I'll need one extra step\n>> > to figure out which commit corresponds to the introduction of which\n>> > file, no?\n>>\n>> Maybe\n>>\n>>   git log --format=%H --name-status --diff-filter=A -- path1 path2 |\n>>   perl -lne '\n>>     if (/[0-9a-f]{40}/) { $commit = $& }\n>>     elsif (/^A\\t(.*)/) { $h{$1} = $commit }\n>>     END { print \"$h{$_} $_\" for keys(%h) }\n>>   '\n>\n> Actually, I only looked at your question, not the original point, which\n> was not which commit was which, but which one was older. If you just\n> want to know which is older, then just:\n>\n>   git log --format=%H --name-status --diff-filter=A -- path1 path2 |\n>   grep ^A |\n>   tail -1\n\nGreat!  I just learnt about --name-status now.\nNit: tail -<n> is deprecated in favor of tail -n <n>, I think.  It's\nnicer to have definite fixed command line options, as opposed to\nparsing an arbitrary -(*) and deciding if \\1 is a \\d+.\n"},{"id":"211865","messageId":"20130321132620.GB23162@sigill.intra.peff.net","threadId":"33241","inReplyTo":"CALkWK0nOzUXk0cFh8GCHc=YqLkRJ2XNFgU_tOsua81ROK99mXw@mail.gmail.com","subject":"Re: Which file is older in history?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-03-21T13:26:20Z","receivedAt":"2013-03-21T13:26:20Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 21, 2013 at 06:02:32PM +0530, Ramkumar Ramachandra wrote:\n\n> >   git log --format=%H --name-status --diff-filter=A -- path1 path2 |\n> >   grep ^A |\n> >   tail -1\n> \n> Great!  I just learnt about --name-status now.\n\nYou can also use \"--name-only\", but the parsing is a little less robust.\n\n> Nit: tail -<n> is deprecated in favor of tail -n <n>, I think.  It's\n> nicer to have definite fixed command line options, as opposed to\n> parsing an arbitrary -(*) and deciding if \\1 is a \\d+.\n\nYeah, POSIX has always specified \"-n\" for tail, as well as for head.  I\nremember in the late 90's and early 00's running into systems where\nPOSIX \"head -n\" did not work, and you _had_ to use \"head -1\". I don't\nrecall now if that was the case for tail, too, nor what system that was\non (but if I had to guess, I'd say pre-Solaris SunOS).\n\nSo yeah. Using \"tail -n 1\" is probably a better idea in the long run.\n\n-Peff\n"}]}