threads / discuss / 9570

Getting a file revision

Subject: Getting a file revision

## tl;dr

11 messages between Aug 19, 2007 and Aug 21, 2007.

replies: 10people: 8as markdown or json

Bahadir Balban· Aug 19, 2007, 00:42 UTC · lore
Hi,

This might sound like a novice question but anyway: I sometimes have a need to quickly recover an old revision of a file just to check something or copy some code from it. I would imagine having a command like:

git-getrev <filename> <commit> or something, and the file would appear in its path, or the git root directory as <filename>.<commit>

Is there an existing way to achieve a similar result? I can certainly checkout a branch, revert to that commit I want, copy the file, and come back to HEAD, but its not as quick.

Thanks, Bahadir

Junio C Hamano· Aug 19, 2007, 00:52 UTC · re: Bahadir Balban · lore

Re: Getting a file revision

"Bahadir Balban" <bahadir.balban@gmail.com> writes:
> This might sound like a novice question but anyway: I sometimes have a
> need to quickly recover an old revision of a file just to check
> something or copy some code from it.
$ git show -p $commit:$path >$path.old-version
Jerome Lovy· Aug 20, 2007, 11:38 UTC · re: Junio C Hamano · lore

Re: Getting a file revision

Hi,
Junio C Hamano wrote:
Show 7 quoted lines
> "Bahadir Balban" <bahadir.balban@gmail.com> writes:
> 
>> This might sound like a novice question but anyway: I sometimes have a
>> need to quickly recover an old revision of a file just to check
>> something or copy some code from it.
> 
> $ git show -p $commit:$path >$path.old-version
Is "-p" a short version of "--pretty" ?

(I do not see it documented in the man-page and assume it is not the "-p" applicable to git-diff-tree, is it ?)

Thanks, Jérôme

Miklos Vajna· Aug 21, 2007, 12:49 UTC · re: Jerome Lovy · lore

[PATCH] Document the -p option for git-show.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
 Documentation/git-show.txt |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-show.txt b/Documentation/git-show.txt
index a42e121..2409389 100644
--- a/Documentation/git-show.txt
+++ b/Documentation/git-show.txt
@@ -33,6 +33,10 @@ This manual page describes only the most frequently used options.
 
 OPTIONS
 -------
+
+-p::
+	For commits, show the change the commit introduces in a patch form.
+
 <object>::
 	The name of the object to show.
 	For a more complete list of ways to spell object names, see
-- 
1.5.2.2
Johannes Sixt· Aug 21, 2007, 13:09 UTC · re: Miklos Vajna · lore

Re: [PATCH] Document the -p option for git-show.

Miklos Vajna wrote:
> +-p::
> +       For commits, show the change the commit introduces in a patch form.

This is already documented by referencing git-diff-tree a few lines above:

	The command takes options applicable to the git-diff-tree[1]
	command to control how the changes the commit introduces are
	shown.
The man page of git-diff-tree talks about -p, and a lot more options.

Side note: -p is the default for git-show (of commits). Nevertheless, it makes sense to specify it in combination with other options:

	git show -p --stat
will show both the patch and the statistics.
-- Hannes
VMiklos· Aug 21, 2007, 14:29 UTC · re: Johannes Sixt · lore

Re: [PATCH] Document the -p option for git-show.

Hello,
Na Tue, Aug 21, 2007 at 03:09:48PM +0200, Johannes Sixt <J.Sixt@eudaptics.com> pisal(a):
Show 13 quoted lines
> This is already documented by referencing git-diff-tree a few lines
> above:
> 
> 	The command takes options applicable to the git-diff-tree[1]
> 	command to control how the changes the commit introduces are
> 	shown.
> (..)
> Side note: -p is the default for git-show (of commits). Nevertheless, it
> makes sense to specify it in combination with other options:
> 
> 	git show -p --stat
> 
> will show both the patch and the statistics.

Hm, but -p is used by default for git show, right? And this is not documented anywhere IMHO. (Maybe other options are used by default, too?)

- VMiklos
David Kastrup· Aug 21, 2007, 15:02 UTC · re: Johannes Sixt · lore

Re: [PATCH] Document the -p option for git-show.

Johannes Sixt <J.Sixt@eudaptics.com> writes:
Show 13 quoted lines
> Miklos Vajna wrote:
>> +-p::
>> +       For commits, show the change the commit introduces in a patch form.
>
> This is already documented by referencing git-diff-tree a few lines
> above:
>
> 	The command takes options applicable to the git-diff-tree[1]
> 	command to control how the changes the commit introduces are
> 	shown.
>
> The man page of git-diff-tree talks about -p, and a lot more
> options.

I am not really convinced this is a good idea: at the current point of time, man-pages are not pulled into they user manual or any other complete reference tome. So they are basically standalone. Even if they weren't, I think it does not make all too much sense for a porcelain command to point to the documentation of a plumbing command for much of its functionality.

-- 
David Kastrup
Robin Rosenberg· Aug 21, 2007, 17:01 UTC · re: Miklos Vajna · lore

Re: [PATCH] Document the -p option for git-show.

tisdag 21 augusti 2007 skrev Miklos Vajna:
Show 20 quoted lines
> Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
> ---
>  Documentation/git-show.txt |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/Documentation/git-show.txt b/Documentation/git-show.txt
> index a42e121..2409389 100644
> --- a/Documentation/git-show.txt
> +++ b/Documentation/git-show.txt
> @@ -33,6 +33,10 @@ This manual page describes only the most frequently used options.
>  
>  OPTIONS
>  -------
> +
> +-p::
> +	For commits, show the change the commit introduces in a patch form.
> +
>  <object>::
>  	The name of the object to show.
>  	For a more complete list of ways to spell object names, see
How about this instead:
-- robin
Include diff options into git-show command manual
--
 Documentation/git-show.txt |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-show.txt b/Documentation/git-show.txt
index a42e121..d4708e0 100644
--- a/Documentation/git-show.txt
+++ b/Documentation/git-show.txt
@@ -41,6 +41,9 @@ OPTIONS
 include::pretty-options.txt[]
 
 
+include::diff-options.txt[]
+
+
 include::pretty-formats.txt[]
 
 
Junio C Hamano· Aug 21, 2007, 17:33 UTC · re: Robin Rosenberg · lore

Re: [PATCH] Document the -p option for git-show.

Robin Rosenberg <robin.rosenberg.lists@dewire.com> writes:
Show 5 quoted lines
> How about this instead:
>
> -- robin
>
> Include diff options into git-show command manual

I think that is probably a good idea but I wonder if placing diff-options in between of pretty-options and pretty-formats is a good idea.

Robin Rosenberg· Aug 21, 2007, 18:50 UTC · re: Junio C Hamano · lore

Re: [PATCH] Document the -p option for git-show.

tisdag 21 augusti 2007 skrev Junio C Hamano:
Show 11 quoted lines
> Robin Rosenberg <robin.rosenberg.lists@dewire.com> writes:
> 
> > How about this instead:
> >
> > -- robin
> >
> > Include diff options into git-show command manual
> 
> I think that is probably a good idea but I wonder if placing
> diff-options in between of pretty-options and pretty-formats is
> a good idea.

Since pretty-formats is a new section in the man page it works out fine. I actually ran make and man to verify this patch.

-- robin
J. Bruce Fields· Aug 19, 2007, 00:52 UTC · re: Bahadir Balban · lore

Re: Getting a file revision

On Sun, Aug 19, 2007 at 01:42:30AM +0100, Bahadir Balban wrote:
Show 11 quoted lines
> This might sound like a novice question but anyway: I sometimes have a
> need to quickly recover an old revision of a file just to check
> something or copy some code from it. I would imagine having a command
> like:
> 
> git-getrev <filename> <commit> or something, and the file would appear
> in its path, or the git root directory as <filename>.<commit>
> 
> Is there an existing way to achieve a similar result? I can certainly
> checkout a branch, revert to that commit I want, copy the file, and
> come back to HEAD, but its not as quick.

Easiest is probably to use git-show together with the <commit>:<filename> syntax, so e.g.:

	git show v1.4:src/main.c
	git show 74ace5df:Makefile >Makefile.tmp
--b.

← back to recent threads