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

Re: How to tell if a file was renamed between two commits

From
RGRon Garret <ron1@flownet.com>
Date
Feb 3, 2010, 02:48 UTC
Message-ID
<ron1-08A0F6.18483502022010@news.gmane.org>
In-Reply-To
<20100203023219.GA13092@spearce.org>
In article <20100203023219.GA13092@spearce.org>,
 "Shawn O. Pearce" <spearce@spearce.org> wrote:
Show 19 quoted lines
> Ron Garret <ron1@flownet.com> wrote:
> > I'm trying to write a little utility that will extract all the revisions 
> > of a particular file.  I start with a git rev-list HEAD -- filename, get 
> > the tree objects with git cat-file commit, the file objects with git 
> > ls-tree, and finally the file contents themselves with git cat-file 
> > blob.  It works, except in the case where the file name was changed.  
> > git rev-list is smart enough to track those name changes, but my little 
> > revision tracker isn't.  It dies when suddenly there is no file with the 
> > right name in the tree.
> > 
> > So... is there an easy way to work around this?  Is there a way to get, 
> > say, rev-list to tell me when the file it is tracking changed names?  Or 
> > a git-diff incantation?  I just need something that will tell me given 
> > two commits and a file name whether the file was renamed between those 
> > two commits and if so what its new name is.  There must be an easy way 
> > to do this, but I can't figure out what it is.
> 
> Maybe use the -M flag to git log, or the --follow flag to
> log/rev-list?

Nope. git log --follow will follow through a name change but won't actually say when the name changed happened or what the previous name of the file was.

And actually playing around with it some more, it appears that git rev-list doesn't actually track file renames, or at least it doesn't do it all the time. Weird. I'm going to have to play around with this some more.

rg
Previous: Shawn O. PearceNext: Ron Garret
Message 3 of 6 in “How to tell if a file was renamed between two commits”
  1. Ron GarretFeb 3, 2010
  2. Shawn O. PearceFeb 3, 2010
  3. Ron GarretFeb 3, 2010
  4. Ron GarretFeb 3, 2010
  5. Shawn O. PearceFeb 3, 2010
  6. Ron GarretFeb 3, 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.