git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Which file is older in history?

From
Jeff King <peff@peff.net>
Date
Mar 21, 2013, 12:24 UTC
Message-ID
<20130321122428.GB22607@sigill.intra.peff.net>
In-Reply-To
<20130321122130.GA22607@sigill.intra.peff.net>
On Thu, Mar 21, 2013 at 08:21:30AM -0400, Jeff King wrote:
Show 18 quoted lines
> 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

which uses the regular traversal order (i.e., mostly following commit timestamps). You can use --topo-order if you want to make sure it follows the graph structure.

-Peff
Previous: Jeff KingNext: Ramkumar Ramachandra
Message 5 of 7 in “Which file is older in history?”
  1. Ramkumar RamachandraMar 20, 2013
  2. Junio C HamanoMar 20, 2013
  3. Ramkumar RamachandraMar 21, 2013
  4. Jeff KingMar 21, 2013
  5. Jeff KingMar 21, 2013
  6. Ramkumar RamachandraMar 21, 2013
  7. Jeff KingMar 21, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.