All of lore.kernel.org
 help / color / mirror / Atom feed
* How do I get the file contents from an arbitrary revision to stdout?
@ 2021-10-08 17:51 Alan Mackenzie
  2021-10-08 18:01 ` Konstantin Ryabitsev
  2021-10-08 20:02 ` Jeff King
  0 siblings, 2 replies; 6+ messages in thread
From: Alan Mackenzie @ 2021-10-08 17:51 UTC (permalink / raw)
  To: git

Hello, git.

I want to get a file's content from a particular revision onto stdout for
backup purposes.  I can't see how to do this.  Help me, please!

Let's say the file is foo.c, and I want to get the version from the head
revision of bar-branch.

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.

Where might I have found this information for myself?

Thanks in advance for the help!

-- 
Alan Mackenzie (Nuremberg, Germany).

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

* Re: How do I get the file contents from an arbitrary revision to stdout?
  2021-10-08 17:51 How do I get the file contents from an arbitrary revision to stdout? Alan Mackenzie
@ 2021-10-08 18:01 ` Konstantin Ryabitsev
  2021-10-08 18:15   ` Alan Mackenzie
  2021-10-08 20:02 ` Jeff King
  1 sibling, 1 reply; 6+ messages in thread
From: Konstantin Ryabitsev @ 2021-10-08 18:01 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: git

On Fri, Oct 08, 2021 at 05:51:17PM +0000, Alan Mackenzie wrote:
> Hello, git.
> 
> I want to get a file's content from a particular revision onto stdout for
> backup purposes.  I can't see how to do this.  Help me, please!
> 
> Let's say the file is foo.c, and I want to get the version from the head
> revision of bar-branch.

git show bar-branch:foo.c

-K

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

* Re: How do I get the file contents from an arbitrary revision to stdout?
  2021-10-08 18:01 ` Konstantin Ryabitsev
@ 2021-10-08 18:15   ` Alan Mackenzie
  0 siblings, 0 replies; 6+ messages in thread
From: Alan Mackenzie @ 2021-10-08 18:15 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: git

Hello, Konstantin.

On Fri, Oct 08, 2021 at 14:01:23 -0400, Konstantin Ryabitsev wrote:
> On Fri, Oct 08, 2021 at 05:51:17PM +0000, Alan Mackenzie wrote:
> > Hello, git.
> > 
> > I want to get a file's content from a particular revision onto stdout for
> > backup purposes.  I can't see how to do this.  Help me, please!
> > 
> > Let's say the file is foo.c, and I want to get the version from the head
> > revision of bar-branch.

> git show bar-branch:foo.c

Thank you indeed.  That works just right!

> -K

-- 
Alan Mackenzie (Nuremberg, Germany).

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

* Re: How do I get the file contents from an arbitrary revision to stdout?
  2021-10-08 17:51 How do I get the file contents from an arbitrary revision to stdout? Alan Mackenzie
  2021-10-08 18:01 ` Konstantin Ryabitsev
@ 2021-10-08 20:02 ` Jeff King
  2021-10-08 21:54   ` Junio C Hamano
  1 sibling, 1 reply; 6+ messages in thread
From: Jeff King @ 2021-10-08 20:02 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: git

On Fri, Oct 08, 2021 at 05:51:17PM +0000, Alan Mackenzie wrote:

> 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

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

* Re: How do I get the file contents from an arbitrary revision to stdout?
  2021-10-08 20:02 ` Jeff King
@ 2021-10-08 21:54   ` Junio C Hamano
  2021-10-08 23:01     ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2021-10-08 21:54 UTC (permalink / raw)
  To: Jeff King; +Cc: Alan Mackenzie, git

Jeff King <peff@peff.net> writes:

>   git cat-file -p bar-branch:foo.c
>
> (the "-p" is "pretty-print based on the object's type", so the two are
> equivalent).

IIRC, "cat-file -p" doesn't do textconv, but "show" would, and
depending on the use case the difference may matter.

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

* Re: How do I get the file contents from an arbitrary revision to stdout?
  2021-10-08 21:54   ` Junio C Hamano
@ 2021-10-08 23:01     ` Jeff King
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff King @ 2021-10-08 23:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Alan Mackenzie, git

On Fri, Oct 08, 2021 at 02:54:51PM -0700, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> >   git cat-file -p bar-branch:foo.c
> >
> > (the "-p" is "pretty-print based on the object's type", so the two are
> > equivalent).
> 
> IIRC, "cat-file -p" doesn't do textconv, but "show" would, and
> depending on the use case the difference may matter.

Sorry, I should have been more clear. I meant that the two cat-file
invocations are equivalent (using "blob" versus "-p").

I agree that for human consumption, "show" is preferable.

-Peff

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

end of thread, other threads:[~2021-10-08 23:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-08 17:51 How do I get the file contents from an arbitrary revision to stdout? Alan Mackenzie
2021-10-08 18:01 ` Konstantin Ryabitsev
2021-10-08 18:15   ` Alan Mackenzie
2021-10-08 20:02 ` Jeff King
2021-10-08 21:54   ` Junio C Hamano
2021-10-08 23:01     ` Jeff King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.