{"thread":{"id":"22432","subject":"Stepping through a single file's history","startedAt":"2010-01-29T01:28:04Z","lastAt":"2010-01-31T08:26:07Z","messageCount":4,"participants":["Ron Garret","John Tapsell","Pete Harlan"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"132931","messageId":"5699F80A-4B27-4BAB-BEE8-5C48938A970B@flownet.com","threadId":"22432","inReplyTo":null,"subject":"Stepping through a single file's history","fromName":"Ron Garret","fromEmail":"ron@flownet.com","sentAt":"2010-01-29T01:28:04Z","receivedAt":"2010-01-29T01:28:04Z","isPatch":false,"sender":{"key":"ron@flownet.com","avatar":null},"body":"Hello,\n\nIs there an easy way to step through the history of a single file?  To be more specific:\n\nSuppose I have a repository with a bunch of files and bunch of commits in a simple linear sequence, but with changes to various files interleaved within that sequence of commits.  I want to be able to step through the history of ONE of the files in the repository without disturbing the other files in the working directory, and without changing the index.  (The use case here is remembering that back in the day there was some useful code in this file that I want to retrieve, but not remembering exactly when it was deleted.  So I want to step back through this file's history and do diffs against HEAD.)\n\nSo I want to be able to do something like...\n\ngit rollback [filename]\n\nand have the copy of the file in the working directory roll back one version.  Then I want to be able to do a 'git diff' and see what was different between that rolled-back version and the most recent one (which I want to then be able to return to somehow, preferably in a more elegant way than git checkout HEAD, but I'll settle for that).\n\nIt seems that this should be possible, but I can't figure out how to do it.  The closest I've been able to come is doing:\n\ngit rev-list HEAD -- [filename]\n\nand then manually going back through the list of commits and doing a git checkout on each one in turn.  There are two problems with this.  First, I have to manually keep track of where I am in the list, which is a PITA if the list is long.  And second, because I've checked the file out, it not only appears in my working directory, but it also gets placed in the index, which is not what I want (because I want to be able to do a git diff against the HEAD to see the code that changed between the old and new versions).\n\nGit does everything, so surely there's a way to do this.  Can anyone offer me a hint as to how?\n\nThanks,\nrg\n"},{"id":"132932","messageId":"43d8ce651001281758x79965b5fn8760b69d4fe82a36@mail.gmail.com","threadId":"22432","inReplyTo":"5699F80A-4B27-4BAB-BEE8-5C48938A970B@flownet.com","subject":"Re: Stepping through a single file's history","fromName":"John Tapsell","fromEmail":"johnflux@gmail.com","sentAt":"2010-01-29T01:58:56Z","receivedAt":"2010-01-29T01:58:56Z","isPatch":false,"sender":{"key":"johnflux@gmail.com","avatar":"https://gravatar.com/avatar/25f70d4c0f96396b84a2e34bcd9bdc233462c7b4be29b5fdca8266fc53f30b0c?d=mp&s=160"},"body":"2010/1/29 Ron Garret <ron@flownet.com>:\n> Hello,\n>\n> Is there an easy way to step through the history of a single file?  To be more specific:\n...\n> (The use case here is remembering that back in the day there was some useful code in this file that I want to retrieve, but not remembering exactly when it was deleted.  So I want to step back through this file's history and do diffs against HEAD.)\n\nHow about simply doing:\n\ngit log -p filename\n\nand then you can search by pressing \"/\"  and then typing whatever you remember.\n\nJohn\n"},{"id":"132938","messageId":"43d8ce651001281947m2505dbcco992ad98ddbfeaeae@mail.gmail.com","threadId":"22432","inReplyTo":"43d8ce651001281758x79965b5fn8760b69d4fe82a36@mail.gmail.com","subject":"Re: Stepping through a single file's history","fromName":"John Tapsell","fromEmail":"johnflux@gmail.com","sentAt":"2010-01-29T03:47:41Z","receivedAt":"2010-01-29T03:47:41Z","isPatch":false,"sender":{"key":"johnflux@gmail.com","avatar":"https://gravatar.com/avatar/25f70d4c0f96396b84a2e34bcd9bdc233462c7b4be29b5fdca8266fc53f30b0c?d=mp&s=160"},"body":"2010/1/29 John Tapsell <johnflux@gmail.com>:\n> 2010/1/29 Ron Garret <ron@flownet.com>:\n>> Hello,\n>>\n>> Is there an easy way to step through the history of a single file?  To be more specific:\n> ...\n>> (The use case here is remembering that back in the day there was some useful code in this file that I want to retrieve, but not remembering exactly when it was deleted.  So I want to step back through this file's history and do diffs against HEAD.)\n>\n> How about simply doing:\n>\n> git log -p filename\n\nYou can also do like:\n\ngit show HEAD~3:path/filename\n\nwhere path is the path from the top of the git repository.  This would\nshow the file as it was 3 revisions ago.\n\nYou can also do like:\n\ngit checkout HEAD~3 filename\n\nto checkout the first as it was 3 revisions ago.\n"},{"id":"133174","messageId":"4B653E9F.2080109@pcharlan.com","threadId":"22432","inReplyTo":"43d8ce651001281758x79965b5fn8760b69d4fe82a36@mail.gmail.com","subject":"Re: Stepping through a single file's history","fromName":"Pete Harlan","fromEmail":"pgit@pcharlan.com","sentAt":"2010-01-31T08:26:07Z","receivedAt":"2010-01-31T08:26:07Z","isPatch":false,"sender":{"key":"pgit@pcharlan.com","avatar":null},"body":"On 01/28/2010 05:58 PM, John Tapsell wrote:\n> 2010/1/29 Ron Garret <ron@flownet.com>:\n>> Hello,\n>> \n>> Is there an easy way to step through the history of a single file?\n>> To be more specific:\n> ...\n>> (The use case here is remembering that back in the day there was\n>> some useful code in this file that I want to retrieve, but not\n>> remembering exactly when it was deleted.  So I want to step back\n>> through this file's history and do diffs against HEAD.)\n> \n> How about simply doing:\n> \n> git log -p filename\n> \n> and then you can search by pressing \"/\"  and then typing whatever you\n> remember.\n> \n> John\n\nHave you tried \"git log -Sfoo filename\", which finds commits that\nchanged the number of occurrances of string \"foo\" in filename?  I've\nfound that quite useful in digging up deleted code.\n\nIt's not as thorough as grepping \"git log -p filename\", but in practice\nI've found it very effective.\n\n--Pete\n"}]}