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

Re: How do I get the file contents from an arbitrary revision to stdout?

From
Jeff King <peff@peff.net>
Date
Oct 8, 2021, 20:02 UTC
Message-ID
<YWCj6NqMrxksN1V8@coredump.intra.peff.net>
In-Reply-To
<YWCFFcNeNVTYcELN@ACM>
On Fri, Oct 08, 2021 at 05:51:17PM +0000, Alan Mackenzie wrote:
Show 7 quoted lines
> I would like there to be a command something like:
> 
>     $ git cat bar-branch -- foo.c
> 
> ..  Is there such a command, and if so, what's it called and how do I use
> it?  I assumed it might be git cat-file, but I couldn't get it to work,
> and couldn't understand it's man page.

Konstantin pointed you at git-show, which is what I would have used. But I just wanted to mention that you were on the right track. The invocation you wanted was:

  git cat-file blob bar-branch:foo.c
or:
  git cat-file -p bar-branch:foo.c

(the "-p" is "pretty-print based on the object's type", so the two are equivalent).

> Where might I have found this information for myself?

You found the cat-file manpage, which I agree is a bit thick. An Examples section would probably help a lot.

The other thing that might have helped is the gitrevisions(7) page, especially the <rev>:<path> entry. Your example above to use "<revs> -- <pathspec>" was a good thought, but the path there is for limiting diffs and traversals. What you want here is to specify the name of a single object, and gitrevisions gives all the ways to do that.

-Peff
Previous: Alan MackenzieNext: Junio C Hamano
Message 4 of 6 in “How do I get the file contents from an arbitrary revision to stdout?”
  1. Alan MackenzieOct 8, 2021
  2. Konstantin RyabitsevOct 8, 2021
  3. Alan MackenzieOct 8, 2021
  4. Jeff KingOct 8, 2021
  5. Junio C HamanoOct 8, 2021
  6. Jeff KingOct 8, 2021

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.