git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Stepping through a single file's history
@ 2010-01-29  1:28 Ron Garret
  2010-01-29  1:58 ` John Tapsell
  0 siblings, 1 reply; 4+ messages in thread
From: Ron Garret @ 2010-01-29  1:28 UTC (permalink / raw)
  To: git

Hello,

Is there an easy way to step through the history of a single file?  To be more specific:

Suppose 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.)

So I want to be able to do something like...

git rollback [filename]

and 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).

It 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:

git rev-list HEAD -- [filename]

and 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).

Git does everything, so surely there's a way to do this.  Can anyone offer me a hint as to how?

Thanks,
rg

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Stepping through a single file's history
  2010-01-29  1:28 Stepping through a single file's history Ron Garret
@ 2010-01-29  1:58 ` John Tapsell
  2010-01-29  3:47   ` John Tapsell
  2010-01-31  8:26   ` Pete Harlan
  0 siblings, 2 replies; 4+ messages in thread
From: John Tapsell @ 2010-01-29  1:58 UTC (permalink / raw)
  Cc: git

2010/1/29 Ron Garret <ron@flownet.com>:
> Hello,
>
> Is there an easy way to step through the history of a single file?  To be more specific:
...
> (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.)

How about simply doing:

git log -p filename

and then you can search by pressing "/"  and then typing whatever you remember.

John

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Stepping through a single file's history
  2010-01-29  1:58 ` John Tapsell
@ 2010-01-29  3:47   ` John Tapsell
  2010-01-31  8:26   ` Pete Harlan
  1 sibling, 0 replies; 4+ messages in thread
From: John Tapsell @ 2010-01-29  3:47 UTC (permalink / raw)
  To: John Tapsell; +Cc: git

2010/1/29 John Tapsell <johnflux@gmail.com>:
> 2010/1/29 Ron Garret <ron@flownet.com>:
>> Hello,
>>
>> Is there an easy way to step through the history of a single file?  To be more specific:
> ...
>> (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.)
>
> How about simply doing:
>
> git log -p filename

You can also do like:

git show HEAD~3:path/filename

where path is the path from the top of the git repository.  This would
show the file as it was 3 revisions ago.

You can also do like:

git checkout HEAD~3 filename

to checkout the first as it was 3 revisions ago.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Stepping through a single file's history
  2010-01-29  1:58 ` John Tapsell
  2010-01-29  3:47   ` John Tapsell
@ 2010-01-31  8:26   ` Pete Harlan
  1 sibling, 0 replies; 4+ messages in thread
From: Pete Harlan @ 2010-01-31  8:26 UTC (permalink / raw)
  To: John Tapsell; +Cc: Ron Garret, git

On 01/28/2010 05:58 PM, John Tapsell wrote:
> 2010/1/29 Ron Garret <ron@flownet.com>:
>> Hello,
>> 
>> Is there an easy way to step through the history of a single file?
>> To be more specific:
> ...
>> (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.)
> 
> How about simply doing:
> 
> git log -p filename
> 
> and then you can search by pressing "/"  and then typing whatever you
> remember.
> 
> John

Have you tried "git log -Sfoo filename", which finds commits that
changed the number of occurrances of string "foo" in filename?  I've
found that quite useful in digging up deleted code.

It's not as thorough as grepping "git log -p filename", but in practice
I've found it very effective.

--Pete

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-01-31  8:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-29  1:28 Stepping through a single file's history Ron Garret
2010-01-29  1:58 ` John Tapsell
2010-01-29  3:47   ` John Tapsell
2010-01-31  8:26   ` Pete Harlan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).