threads / discuss / 11757

Contents of file for a commit

Subject: Contents of file for a commit

## tl;dr

6 messages between Jan 27, 2008 and Jan 27, 2008.

replies: 5people: 3as markdown or json

Bill Lear· Jan 27, 2008, 04:22 UTC · lore

How can I do the equivalent of 'cvs co -r <commit> -p <file>' in git? I want to see the entire contents of a file as it existed after a particular commit was introduced.

Bill
Jeff King· Jan 27, 2008, 04:28 UTC · re: Bill Lear · lore

Re: Contents of file for a commit

On Sat, Jan 26, 2008 at 10:22:58PM -0600, Bill Lear wrote:
> How can I do the equivalent of 'cvs co -r <commit> -p <file>' in git?
> I want to see the entire contents of a file as it existed after a
> particular commit was introduced.
Try 'git show <commit>:<file>'.
-Peff
Shawn O. Pearce· Jan 27, 2008, 04:40 UTC · re: Bill Lear · lore

Re: Contents of file for a commit

Bill Lear <rael@zopyra.com> wrote:
> How can I do the equivalent of 'cvs co -r <commit> -p <file>' in git?
> I want to see the entire contents of a file as it existed after a
> particular commit was introduced.
`git checkout $commit -- $path`

would get the file at that version into your working directory, but also will update the index, thus staging the file for the next commit.

You can also just view the file if you don't want those changes to be made:

`git show $commit -- $path`

If you are scripting, use cat-file directly to avoid any CRLF conversion or whatnot:

`git cat-file blob $commit:$path`
-- 
Shawn.
Jeff King· Jan 27, 2008, 04:49 UTC · re: Shawn O. Pearce · lore

Re: Contents of file for a commit

On Sat, Jan 26, 2008 at 11:40:27PM -0500, Shawn O. Pearce wrote:
> You can also just view the file if you don't want those changes
> to be made:
> 
> `git show $commit -- $path`

That doesn't work. It says "show me $commit, but limited by $path". So if $path was changed, you see the commit log and diff. If it wasn't, you see nothing.

-Peff
Shawn O. Pearce· Jan 27, 2008, 05:01 UTC · re: Jeff King · lore

Re: Contents of file for a commit

Jeff King <peff@peff.net> wrote:
Show 10 quoted lines
> On Sat, Jan 26, 2008 at 11:40:27PM -0500, Shawn O. Pearce wrote:
> 
> > You can also just view the file if you don't want those changes
> > to be made:
> > 
> > `git show $commit -- $path`
> 
> That doesn't work. It says "show me $commit, but limited by $path". So
> if $path was changed, you see the commit log and diff. If it wasn't, you
> see nothing.
Gah.  Indeed.  I should have suggested to Bill:
`git show $commit:$path`
sorry about the confusion, and thanks for the clarification.  :-)
-- 
Shawn.
Bill Lear· Jan 27, 2008, 14:31 UTC · re: Shawn O. Pearce · lore

Re: Contents of file for a commit

On Sunday, January 27, 2008 at 00:01:28 (-0500) Shawn O. Pearce writes:
Show 17 quoted lines
>Jeff King <peff@peff.net> wrote:
>> On Sat, Jan 26, 2008 at 11:40:27PM -0500, Shawn O. Pearce wrote:
>> 
>> > You can also just view the file if you don't want those changes
>> > to be made:
>> > 
>> > `git show $commit -- $path`
>> 
>> That doesn't work. It says "show me $commit, but limited by $path". So
>> if $path was changed, you see the commit log and diff. If it wasn't, you
>> see nothing.
>
>Gah.  Indeed.  I should have suggested to Bill:
>
>`git show $commit:$path`
>
>sorry about the confusion, and thanks for the clarification.  :-)
Ok, looks like that works.  Thanks all.
Bill

← back to recent threads