{"thread":{"id":"56668","subject":"How do I get the file contents from an arbitrary revision to stdout?","startedAt":"2021-10-08T17:58:02Z","lastAt":"2021-10-08T23:01:10Z","messageCount":6,"participants":["Alan Mackenzie","Konstantin Ryabitsev","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"438303","messageId":"YWCFFcNeNVTYcELN@ACM","threadId":"56668","inReplyTo":null,"subject":"How do I get the file contents from an arbitrary revision to stdout?","fromName":"Alan Mackenzie","fromEmail":"acm@muc.de","sentAt":"2021-10-08T17:51:17Z","receivedAt":"2021-10-08T17:58:02Z","isPatch":false,"sender":{"key":"acm@muc.de","avatar":null},"body":"Hello, git.\n\nI want to get a file's content from a particular revision onto stdout for\nbackup purposes.  I can't see how to do this.  Help me, please!\n\nLet's say the file is foo.c, and I want to get the version from the head\nrevision of bar-branch.\n\nI would like there to be a command something like:\n\n    $ git cat bar-branch -- foo.c\n\n..  Is there such a command, and if so, what's it called and how do I use\nit?  I assumed it might be git cat-file, but I couldn't get it to work,\nand couldn't understand it's man page.\n\nWhere might I have found this information for myself?\n\nThanks in advance for the help!\n\n-- \nAlan Mackenzie (Nuremberg, Germany).\n"},{"id":"438304","messageId":"20211008180123.ls62virahqthgpmb@meerkat.local","threadId":"56668","inReplyTo":"YWCFFcNeNVTYcELN@ACM","subject":"Re: How do I get the file contents from an arbitrary revision to stdout?","fromName":"Konstantin Ryabitsev","fromEmail":"konstantin@linuxfoundation.org","sentAt":"2021-10-08T18:01:23Z","receivedAt":"2021-10-08T18:01:29Z","isPatch":false,"sender":{"key":"konstantin@linuxfoundation.org","avatar":"https://gravatar.com/avatar/7cb8827c6de56e1bd2dea16508c6708aa43feed3bf3813bcdacecdf96ceadd79?d=mp&s=160"},"body":"On Fri, Oct 08, 2021 at 05:51:17PM +0000, Alan Mackenzie wrote:\n> Hello, git.\n> \n> I want to get a file's content from a particular revision onto stdout for\n> backup purposes.  I can't see how to do this.  Help me, please!\n> \n> Let's say the file is foo.c, and I want to get the version from the head\n> revision of bar-branch.\n\ngit show bar-branch:foo.c\n\n-K\n"},{"id":"438306","messageId":"YWCKpH5ER1Z9Xm3E@ACM","threadId":"56668","inReplyTo":"20211008180123.ls62virahqthgpmb@meerkat.local","subject":"Re: How do I get the file contents from an arbitrary revision to stdout?","fromName":"Alan Mackenzie","fromEmail":"acm@muc.de","sentAt":"2021-10-08T18:15:00Z","receivedAt":"2021-10-08T18:15:03Z","isPatch":false,"sender":{"key":"acm@muc.de","avatar":null},"body":"Hello, Konstantin.\n\nOn Fri, Oct 08, 2021 at 14:01:23 -0400, Konstantin Ryabitsev wrote:\n> On Fri, Oct 08, 2021 at 05:51:17PM +0000, Alan Mackenzie wrote:\n> > Hello, git.\n> > \n> > I want to get a file's content from a particular revision onto stdout for\n> > backup purposes.  I can't see how to do this.  Help me, please!\n> > \n> > Let's say the file is foo.c, and I want to get the version from the head\n> > revision of bar-branch.\n\n> git show bar-branch:foo.c\n\nThank you indeed.  That works just right!\n\n> -K\n\n-- \nAlan Mackenzie (Nuremberg, Germany).\n"},{"id":"438335","messageId":"YWCj6NqMrxksN1V8@coredump.intra.peff.net","threadId":"56668","inReplyTo":"YWCFFcNeNVTYcELN@ACM","subject":"Re: How do I get the file contents from an arbitrary revision to stdout?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-10-08T20:02:48Z","receivedAt":"2021-10-08T20:02:50Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Oct 08, 2021 at 05:51:17PM +0000, Alan Mackenzie wrote:\n\n> I would like there to be a command something like:\n> \n>     $ git cat bar-branch -- foo.c\n> \n> ..  Is there such a command, and if so, what's it called and how do I use\n> it?  I assumed it might be git cat-file, but I couldn't get it to work,\n> and couldn't understand it's man page.\n\nKonstantin pointed you at git-show, which is what I would have used. But\nI just wanted to mention that you were on the right track. The\ninvocation you wanted was:\n\n  git cat-file blob bar-branch:foo.c\n\nor:\n\n  git cat-file -p bar-branch:foo.c\n\n(the \"-p\" is \"pretty-print based on the object's type\", so the two are\nequivalent).\n\n> Where might I have found this information for myself?\n\nYou found the cat-file manpage, which I agree is a bit thick. An\nExamples section would probably help a lot.\n\nThe other thing that might have helped is the gitrevisions(7) page,\nespecially the <rev>:<path> entry. Your example above to use \"<revs> --\n<pathspec>\" was a good thought, but the path there is for limiting diffs\nand traversals. What you want here is to specify the name of a single\nobject, and gitrevisions gives all the ways to do that.\n\n-Peff\n"},{"id":"438368","messageId":"xmqqtuhri3mc.fsf@gitster.g","threadId":"56668","inReplyTo":"YWCj6NqMrxksN1V8@coredump.intra.peff.net","subject":"Re: How do I get the file contents from an arbitrary revision to stdout?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-10-08T21:54:51Z","receivedAt":"2021-10-08T21:54:55Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n>   git cat-file -p bar-branch:foo.c\n>\n> (the \"-p\" is \"pretty-print based on the object's type\", so the two are\n> equivalent).\n\nIIRC, \"cat-file -p\" doesn't do textconv, but \"show\" would, and\ndepending on the use case the difference may matter.\n"},{"id":"438380","messageId":"YWDM0HASo7VMwnz1@coredump.intra.peff.net","threadId":"56668","inReplyTo":"xmqqtuhri3mc.fsf@gitster.g","subject":"Re: How do I get the file contents from an arbitrary revision to stdout?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-10-08T23:01:06Z","receivedAt":"2021-10-08T23:01:10Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Oct 08, 2021 at 02:54:51PM -0700, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> >   git cat-file -p bar-branch:foo.c\n> >\n> > (the \"-p\" is \"pretty-print based on the object's type\", so the two are\n> > equivalent).\n> \n> IIRC, \"cat-file -p\" doesn't do textconv, but \"show\" would, and\n> depending on the use case the difference may matter.\n\nSorry, I should have been more clear. I meant that the two cat-file\ninvocations are equivalent (using \"blob\" versus \"-p\").\n\nI agree that for human consumption, \"show\" is preferable.\n\n-Peff\n"}]}