From: Ramkumar Ramachandra Date: Thu, 21 Mar 2013 12:32:32 GMT Subject: Re: Which file is older in history? Message-ID: In-Reply-To: <20130321122428.GB22607@sigill.intra.peff.net> Jeff King wrote: > On Thu, Mar 21, 2013 at 08:21:30AM -0400, Jeff King wrote: > >> On Thu, Mar 21, 2013 at 05:29:39PM +0530, Ramkumar Ramachandra wrote: >> >> > > This must be a trick question but the naïve way I think of is >> > > >> > > git log --diff-filter=A -- path1 path2 >> > >> > Thanks, I didn't know about --diff-filter. I'll need one extra step >> > to figure out which commit corresponds to the introduction of which >> > file, no? >> >> Maybe >> >> git log --format=%H --name-status --diff-filter=A -- path1 path2 | >> perl -lne ' >> if (/[0-9a-f]{40}/) { $commit = $& } >> elsif (/^A\t(.*)/) { $h{$1} = $commit } >> END { print "$h{$_} $_" for keys(%h) } >> ' > > Actually, I only looked at your question, not the original point, which > was not which commit was which, but which one was older. If you just > want to know which is older, then just: > > git log --format=%H --name-status --diff-filter=A -- path1 path2 | > grep ^A | > tail -1 Great! I just learnt about --name-status now. Nit: tail - is deprecated in favor of tail -n , I think. It's nicer to have definite fixed command line options, as opposed to parsing an arbitrary -(*) and deciding if \1 is a \d+.