{"thread":{"id":"22499","subject":"How to tell if a file was renamed between two commits","startedAt":"2010-02-03T02:29:20Z","lastAt":"2010-02-03T17:48:22Z","messageCount":6,"participants":["Ron Garret","Shawn O. Pearce"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"133436","messageId":"ron1-2EA926.18292002022010@news.gmane.org","threadId":"22499","inReplyTo":null,"subject":"How to tell if a file was renamed between two commits","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-03T02:29:20Z","receivedAt":"2010-02-03T02:29:20Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"I'm trying to write a little utility that will extract all the revisions \nof a particular file.  I start with a git rev-list HEAD -- filename, get \nthe tree objects with git cat-file commit, the file objects with git \nls-tree, and finally the file contents themselves with git cat-file \nblob.  It works, except in the case where the file name was changed.  \ngit rev-list is smart enough to track those name changes, but my little \nrevision tracker isn't.  It dies when suddenly there is no file with the \nright name in the tree.\n\nSo... is there an easy way to work around this?  Is there a way to get, \nsay, rev-list to tell me when the file it is tracking changed names?  Or \na git-diff incantation?  I just need something that will tell me given \ntwo commits and a file name whether the file was renamed between those \ntwo commits and if so what its new name is.  There must be an easy way \nto do this, but I can't figure out what it is.\n\nThanks,\nrg\n"},{"id":"133437","messageId":"20100203023219.GA13092@spearce.org","threadId":"22499","inReplyTo":"ron1-2EA926.18292002022010@news.gmane.org","subject":"Re: How to tell if a file was renamed between two commits","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2010-02-03T02:32:19Z","receivedAt":"2010-02-03T02:32:19Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Ron Garret <ron1@flownet.com> wrote:\n> I'm trying to write a little utility that will extract all the revisions \n> of a particular file.  I start with a git rev-list HEAD -- filename, get \n> the tree objects with git cat-file commit, the file objects with git \n> ls-tree, and finally the file contents themselves with git cat-file \n> blob.  It works, except in the case where the file name was changed.  \n> git rev-list is smart enough to track those name changes, but my little \n> revision tracker isn't.  It dies when suddenly there is no file with the \n> right name in the tree.\n> \n> So... is there an easy way to work around this?  Is there a way to get, \n> say, rev-list to tell me when the file it is tracking changed names?  Or \n> a git-diff incantation?  I just need something that will tell me given \n> two commits and a file name whether the file was renamed between those \n> two commits and if so what its new name is.  There must be an easy way \n> to do this, but I can't figure out what it is.\n\nMaybe use the -M flag to git log, or the --follow flag to\nlog/rev-list?\n\n-- \nShawn.\n"},{"id":"133438","messageId":"ron1-08A0F6.18483502022010@news.gmane.org","threadId":"22499","inReplyTo":"20100203023219.GA13092@spearce.org","subject":"Re: How to tell if a file was renamed between two commits","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-03T02:48:35Z","receivedAt":"2010-02-03T02:48:35Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"In article <20100203023219.GA13092@spearce.org>,\n \"Shawn O. Pearce\" <spearce@spearce.org> wrote:\n\n> Ron Garret <ron1@flownet.com> wrote:\n> > I'm trying to write a little utility that will extract all the revisions \n> > of a particular file.  I start with a git rev-list HEAD -- filename, get \n> > the tree objects with git cat-file commit, the file objects with git \n> > ls-tree, and finally the file contents themselves with git cat-file \n> > blob.  It works, except in the case where the file name was changed.  \n> > git rev-list is smart enough to track those name changes, but my little \n> > revision tracker isn't.  It dies when suddenly there is no file with the \n> > right name in the tree.\n> > \n> > So... is there an easy way to work around this?  Is there a way to get, \n> > say, rev-list to tell me when the file it is tracking changed names?  Or \n> > a git-diff incantation?  I just need something that will tell me given \n> > two commits and a file name whether the file was renamed between those \n> > two commits and if so what its new name is.  There must be an easy way \n> > to do this, but I can't figure out what it is.\n> \n> Maybe use the -M flag to git log, or the --follow flag to\n> log/rev-list?\n\nNope.  git log --follow will follow through a name change but won't \nactually say when the name changed happened or what the previous name of \nthe file was.\n\nAnd actually playing around with it some more, it appears that git \nrev-list doesn't actually track file renames, or at least it doesn't do \nit all the time.  Weird.  I'm going to have to play around with this \nsome more.\n\nrg\n"},{"id":"133440","messageId":"ron1-5818AE.18520202022010@news.gmane.org","threadId":"22499","inReplyTo":"ron1-08A0F6.18483502022010@news.gmane.org","subject":"Re: How to tell if a file was renamed between two commits","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-03T02:52:02Z","receivedAt":"2010-02-03T02:52:02Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"In article <ron1-08A0F6.18483502022010@news.gmane.org>,\n Ron Garret <ron1@flownet.com> wrote:\n\n> In article <20100203023219.GA13092@spearce.org>,\n>  \"Shawn O. Pearce\" <spearce@spearce.org> wrote:\n> \n> > Ron Garret <ron1@flownet.com> wrote:\n> > > I'm trying to write a little utility that will extract all the revisions \n> > > of a particular file.  I start with a git rev-list HEAD -- filename, get \n> > > the tree objects with git cat-file commit, the file objects with git \n> > > ls-tree, and finally the file contents themselves with git cat-file \n> > > blob.  It works, except in the case where the file name was changed.  \n> > > git rev-list is smart enough to track those name changes, but my little \n> > > revision tracker isn't.  It dies when suddenly there is no file with the \n> > > right name in the tree.\n> > > \n> > > So... is there an easy way to work around this?  Is there a way to get, \n> > > say, rev-list to tell me when the file it is tracking changed names?  Or \n> > > a git-diff incantation?  I just need something that will tell me given \n> > > two commits and a file name whether the file was renamed between those \n> > > two commits and if so what its new name is.  There must be an easy way \n> > > to do this, but I can't figure out what it is.\n> > \n> > Maybe use the -M flag to git log, or the --follow flag to\n> > log/rev-list?\n> \n> Nope.  git log --follow will follow through a name change but won't \n> actually say when the name changed happened or what the previous name of \n> the file was.\n> \n> And actually playing around with it some more, it appears that git \n> rev-list doesn't actually track file renames, or at least it doesn't do \n> it all the time.  Weird.  I'm going to have to play around with this \n> some more.\n> \n> rg\n\nAh, I think I found it:\n\ngit log --follow --raw -- [filename]\n\ngives you e.g.:\n\n:100644 100644 01e79c3... 01e79c3... R100       foo     baz\n\nwhich seems to be what I'm looking for.\n\nrg\n"},{"id":"133439","messageId":"20100203025347.GB13092@spearce.org","threadId":"22499","inReplyTo":"ron1-08A0F6.18483502022010@news.gmane.org","subject":"Re: How to tell if a file was renamed between two commits","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2010-02-03T02:53:47Z","receivedAt":"2010-02-03T02:53:47Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Ron Garret <ron1@flownet.com> wrote:\n> In article <20100203023219.GA13092@spearce.org>,\n>  \"Shawn O. Pearce\" <spearce@spearce.org> wrote:\n> > > So... is there an easy way to work around this?  Is there a way to get, \n> > > say, rev-list to tell me when the file it is tracking changed names?\n> > \n> > Maybe use the -M flag to git log, or the --follow flag to\n> > log/rev-list?\n> \n> Nope.  git log --follow will follow through a name change but won't \n> actually say when the name changed happened or what the previous name of \n> the file was.\n> \n> And actually playing around with it some more, it appears that git \n> rev-list doesn't actually track file renames, or at least it doesn't do \n> it all the time.  Weird.  I'm going to have to play around with this \n> some more.\n\nUse:\n\n  git log --format=%H -M --name-status --follow -- path \n\nI just tried it:\n\n$ git log --format=%H -M --name-status --follow gerrit-prettify/src/main/resources/com/google/gerrit/prettify/client/prettify.js\n8db22c85c49814b99639b2e6346583e9be4c289f\n\nR100    gerrit-patch-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/\n544546fcd680f82a88df3e9eba7df8acfadf1e46\n\nM       gerrit-patch-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/\nd83ac11a52c1b6d4acae932a8495daf1e9129fdf\n\nR100    gerrit-patch-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/public/\n44671f5c6929a8f05223dd359182610286ceb98a\n\nR100    src/main/java/com/google/gerrit/public/prettify20090521/prettify.js     \n56fc9e3d951b0886c4781a5c8623dbc3da824f30\n\nA       src/main/java/com/google/gerrit/public/prettify20090521/prettify.js\n\n\nYay, its been renamed 3 times in its life here.  :-)\n\n-- \nShawn.\n"},{"id":"133485","messageId":"ron1-F82E20.09482203022010@news.gmane.org","threadId":"22499","inReplyTo":"20100203025347.GB13092@spearce.org","subject":"Re: How to tell if a file was renamed between two commits","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-03T17:48:22Z","receivedAt":"2010-02-03T17:48:22Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"In article <20100203025347.GB13092@spearce.org>,\n \"Shawn O. Pearce\" <spearce@spearce.org> wrote:\n\n> Ron Garret <ron1@flownet.com> wrote:\n> > In article <20100203023219.GA13092@spearce.org>,\n> >  \"Shawn O. Pearce\" <spearce@spearce.org> wrote:\n> > > > So... is there an easy way to work around this?  Is there a way to get, \n> > > > say, rev-list to tell me when the file it is tracking changed names?\n> > > \n> > > Maybe use the -M flag to git log, or the --follow flag to\n> > > log/rev-list?\n> > \n> > Nope.  git log --follow will follow through a name change but won't \n> > actually say when the name changed happened or what the previous name of \n> > the file was.\n> > \n> > And actually playing around with it some more, it appears that git \n> > rev-list doesn't actually track file renames, or at least it doesn't do \n> > it all the time.  Weird.  I'm going to have to play around with this \n> > some more.\n> \n> Use:\n> \n>   git log --format=%H -M --name-status --follow -- path \n> \n> I just tried it:\n> \n> $ git log --format=%H -M --name-status --follow \n> gerrit-prettify/src/main/resources/com/google/gerrit/prettify/client/prettify.\n> js\n> 8db22c85c49814b99639b2e6346583e9be4c289f\n> \n> R100    \n> gerrit-patch-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/\n> 544546fcd680f82a88df3e9eba7df8acfadf1e46\n> \n> M       \n> gerrit-patch-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/\n> d83ac11a52c1b6d4acae932a8495daf1e9129fdf\n> \n> R100    \n> gerrit-patch-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/public/\n> 44671f5c6929a8f05223dd359182610286ceb98a\n> \n> R100    src/main/java/com/google/gerrit/public/prettify20090521/prettify.js   \n>   \n> 56fc9e3d951b0886c4781a5c8623dbc3da824f30\n> \n> A       src/main/java/com/google/gerrit/public/prettify20090521/prettify.js\n> \n> \n> Yay, its been renamed 3 times in its life here.  :-)\n\nCool!  Thanks!\n\nrg\n"}]}