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

Re: How do get a specific version of a particular file?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Feb 27, 2007, 16:38 UTC
Message-ID
<Pine.LNX.4.64.0702270830260.12485@woody.linux-foundation.org>
In-Reply-To
<E1HM1XL-00071C-N5@candygram.thunk.org>
On Tue, 27 Feb 2007, Theodore Ts'o wrote:
> 
> git-checkout will only write the output to the working tree.
> git-cat-file and git-show only work on a object identifier (they are
> low-level plumbing commands).  

Everybody has already pointed out how easy this actually is, but your fundamental mistake was thinking that "only work on a object identifier" is a bad thing.

Repeat after me: in git, *everything* is a SHA1 object!

So the problem you had was that "only". Remove the "only", and realize that object identifiers will cover _all_ you ever need, and be happy.

That's why
	git show <tree>:<path>

works. All the files are *also* just SHA1 objects, and as a result all the normal SHA1 naming rules apply.

This is also why you can literally do
	git diff v1.4.4:Makefile HEAD~5:Makefile

and it will just magically work and do exactly what the command line would make you think it does - even if you didn't know anything at all about git.

Because "git diff" knows about blob objects too, and "v1.3:Makefile" is the object name for the blob that was the Makefile object at version 1.4.4, and HEAD~5:Makefile is the Makefile in the fifth parent of your current HEAD.

Tell me any other SCM that makes things quite _that_ easy?

So in Unix, we have "everything is a file" (and then we have processes). In git, we have "everything is a SHA1-named object" (and then we have revision walking). There's a really simple underlying logic to it all, and the great thing is how _powerful_ it is.

THIS is what good design is all about. Forget nipples. You just need to internalize the fact that "everything is a SHA1".

> So if it is a matter of we don't have an easy way to do this (as opposed
> to me being stupid or the git documentation just failing to mention it
> in the right places), what's the best way to add it?

So not only do we have it, it's probably not mentioned in the docs because it is *so* fundamental that nobody even thought to mention any of this except in the "how does SHA1 lookup work" sections.

			Linus
Previous: Theodore TsoNext: Bill Lear
Message 29 of 32 in “How do get a specific version of a particular file?”
  1. Theodore Ts'oFeb 27, 2007
  2. Christian MICHONFeb 27, 2007
  3. Peter BaumannFeb 27, 2007
  4. Alex RiesenFeb 27, 2007
  5. Alex RiesenFeb 27, 2007
  6. Johannes SchindelinFeb 27, 2007
  7. Theodore TsoFeb 27, 2007
  8. Johannes SchindelinFeb 27, 2007
  9. Theodore TsoFeb 27, 2007
  10. Randal L. SchwartzFeb 27, 2007
  11. Junio C HamanoFeb 27, 2007
  12. Linus TorvaldsFeb 28, 2007
  13. Junio C HamanoFeb 28, 2007
  14. Johannes SchindelinFeb 28, 2007
  15. Linus TorvaldsFeb 28, 2007
  16. Nicolas PitreFeb 28, 2007
  17. Linus TorvaldsFeb 28, 2007
  18. Nicolas PitreFeb 28, 2007
  19. Theodore TsoFeb 28, 2007
  20. Junio C HamanoFeb 28, 2007
  21. Theodore TsoFeb 28, 2007
  22. Junio C HamanoFeb 28, 2007
  23. Nicolas PitreFeb 28, 2007
  24. Johannes SchindelinFeb 28, 2007
  25. Linus TorvaldsFeb 28, 2007
  26. Junio C HamanoFeb 28, 2007
  27. Johannes SchindelinFeb 28, 2007
  28. Fix git-show man page formatting in the EXAMPLES sectionTheodore Tso, Feb 27, 2007
  29. Linus TorvaldsFeb 27, 2007
  30. Bill LearFeb 27, 2007
  31. Theodore TsoFeb 27, 2007
  32. Linus TorvaldsFeb 27, 2007

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.