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

Stepping through a single file's history

From
RGRon Garret <ron@flownet.com>
Date
Jan 29, 2010, 01:28 UTC
Message-ID
<5699F80A-4B27-4BAB-BEE8-5C48938A970B@flownet.com>
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

Next: John Tapsell
Message 1 of 4 in “Stepping through a single file's history”
  1. Ron GarretJan 29, 2010
  2. John TapsellJan 29, 2010
  3. John TapsellJan 29, 2010
  4. Pete HarlanJan 31, 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.