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

Re: Listing files in order they are changed

From
Jeff King <peff@peff.net>
Date
Sep 23, 2010, 20:38 UTC
Message-ID
<20100923203814.GA10951@sigill.intra.peff.net>
In-Reply-To
<AANLkTimHrCujEggj9KbAWWivY+WxnL0YqsXs+idhymBA@mail.gmail.com>
On Thu, Sep 23, 2010 at 11:51:56AM -0700, Parag Kalra wrote:
> Is there a way I can make Git list all the tracked files in the
> working directory in order they are changed (modified, added or
> deleted)

It's a somewhat expensive operation, since you have to walk history backwards looking at changes. But try:

git log --pretty=format: --name-only |
  grep . |
  perl -ne 'print unless $seen{$_}++'

which will walk history backwards, printing out each filename the most recent time it is encountered. Which should give you a list of all files in the repo (including ones which no longer exist!), in order of most recent to oldest.

If you want to restrict only to existing files, you would have to do some clever path-limiting, or parse the results with a slightly smarter perl script.

You can also tweak the definition of "most recent" by using --topo-order or --date-order with git log.

-Peff
Previous: Parag KalraNext: Peter Krefting
Message 2 of 7 in “Listing files in order they are changed”
  1. Parag KalraSep 23, 2010
  2. Jeff KingSep 23, 2010
  3. Peter KreftingSep 24, 2010
  4. Jakub NarebskiSep 23, 2010
  5. Sverre RabbelierSep 23, 2010
  6. Jakub NarebskiSep 23, 2010
  7. Sverre RabbelierSep 23, 2010

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.